jquery autocomplete doesn't work?
I want to make autocomlplete for remote data source, I get all data from database and return it as jSon, using console I see that all data has been returned, but the autocomplete doesn't work, also the alert in my code doesn't work, here's my code
$("#cellPhoneNo").autocomplete({
source: function(request, response) {
var param = {
"action": "getCellPhoneNos"
};
$.getJSON("controllers/Customer.controller.php", param, function(result) {
alert('here'); //doesn't alert
// cellPhoneSource=result;
});
},
select: function(event, ui) {
alert('response');
}
});
EDIT
I try to get the source using GET , I make like this
source:function(request,response){
var param= {"action":"getCellPhoneNos"};
$.ajax({
type: "GET",
url: "controllers/Customer.controller.php",
data: param,
success: function(result){
alert('success');
}
});
},
it alerts but aut开发者_开发问答ocomplete doesn't work, I try to put the values in a text file and make the file in the url , the autocomplete works!!
Any explanation?!
http://net.tutsplus.com/tutorials/javascript-ajax/how-to-use-the-jquery-ui-autocomplete-widget/
This is a tutorial on using the autocomplete plugin. The response
variable in your callback is a function that you can call to add an array of items to the autocomplete list. Parse result
and push each item onto an array, then call response(array);
If result is already an array, you can call response(result);
I noticed that in the success function you do not return the result from the ajax query, could that be an issue?
source : function(request,response) {
var param= {"action":"getCellPhoneNos"};
var source = 'nothing came back from the server';
$.ajax({
type: "GET",
url: "controllers/Customer.controller.php",
data: param,
datatype: 'json'
success: function(result) {
if(result !== undefined) {
source = result;
}
alert(source);
return source;
}
});
},
精彩评论