[英]Send This array to php and get results in div (FCBKcomplete)
I'm using an autosuggest plugin that allows me to select multiple items from a dropdown menu ( demo here ). 我正在使用一个autosuggest插件,该插件使我可以从下拉菜单中选择多个项目( 此处为演示 )。 I want a query to be sent to a php file (I will be preoccupied with the query itself later) and get a result back without leaving the page. 我希望将查询发送到php文件(稍后我将全神贯注于查询本身),并在不离开页面的情况下获得返回结果。
The php file is pretty much empty right now: php文件现在几乎是空的:
<?php print_r($_REQUEST); ?>
But I know I made a mistake with my jquery somewhere since the search box is not displaying properly anymore . 但是我知道我的jquery犯了一个错误,因为搜索框不再正确显示 。
Here's the code I built up, I'm not sure what to put in the "data" field. 这是我建立的代码,我不确定要在“数据”字段中输入什么。
<script type="text/javascript">
$(document).ready(function(){
$("#select3").fcbkcomplete({
json_url: "data.txt",
addontab: true,
maxitems: 10,
input_min_size: 0,
height: 10,
cache: true,
newel: false,
filter_selected: true,
maxitimes: 5,
// I did this
onselect:"get_venue",
});
// I also did this
function get_venue() {
$("#select3 option:selected").each(function() {
$.ajax({
type: 'POST',
url: 'post.php',
dataType: 'json',
data: {
WHAT DATA GOES HERE?
},
success : function(data){
$('#phpmessage').removeClass().addClass((data.error === true) ? 'error' : 'success')
.text(data.msg).show(500);
if (data.error === true)
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
$('#waiting').hide(500);
$('#phpmessage').removeClass().addClass('error')
.text('There was an error.').show(500);
}
});
});
}
});
</script>
Sorry for such a long post everybody :)!! 对不起,这么长的帖子大家:)! Thanks :)) 谢谢 :))
Error I'm getting: 我得到的错误:
Is not a function: return func.call(func, _object); 不是函数: return func.call(func,_object);
function funCall(func, item) {
var _object = {};
for (i = 0; i < item.get(0).attributes.length; i++) {
if (item.get(0).attributes[i].nodeValue != null) {
_object["_" + item.get(0).attributes[i].nodeName] = item.get(0).attributes[i].nodeValue;
}
}
return func.call(func, _object);
}
function checkFocusOn() {
if (focuson == null || focuson.length == 0) {
return false;
}
return true;
}
You want to loop over each of the items in the search box, these have a class of .bit-box
. 您想遍历搜索框中的每个项目,这些项目具有.bit-box
类。 Create an array of these search terms then send them in as data into the ajax request. 创建这些搜索词的数组,然后将它们作为数据发送到ajax请求中。
function get_venue() {
var data = [];
$('.bit-box').each(function() {
data.push( $(this).text );
});
$.ajax({
type: 'POST',
url: 'post.php',
dataType: 'json',
data: {
'choices[]': data
},
success : function(data){
$('#phpmessage')
.removeClass()
.addClass((data.error === true) ? 'error' : 'success')
.text(data.msg).show(500);
if (data.error === true){
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
$('#waiting').hide(500);
$('#phpmessage').removeClass().addClass('error')
.text('There was an error.').show(500);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.