Reputation: 26312
I am trying to make autocomplete using jqueryUi, but unable to bind data to it.
$("#CustomerName").autocomplete({
source:
function () {
$.ajax({
url: "SearchCustomer?key=" + $("#CustomerName").val(),
async: false,
dataType:"json",
success: function (data) {
return data.ResultList;
}
})
},
minLength: 0, autoFocus: true, delay: 1000
});
My Result of ajax is -
{"Message":null,"Successfull":false,"Id":0,"Result":null,"ResultList":["Customer 2","Kohl\u0027s Corp","Test Corp"]}
if i use this, then it work fine
$("#CustomerName").autocomplete({
source:["Customer 2","Kohl\u0027s Corp","Test Corp"],
minLength: 0, autoFocus: true, delay: 1000
});
Thanks in advance !
Upvotes: 2
Views: 286
Reputation: 8346
Nothing wrong with $.ajax, could you please wrap the returned data with the response like response(data.ResultList);
$("#CustomerName").autocomplete({
source: function( request, response ) {
$.ajax({
url: "SearchCustomer?key=" + $("#CustomerName").val(),
dataType : "json",
success: function (data) {
response(data.ResultList);
}
});
},
minLength: 0,
autoFocus: true,
delay: 1000
});
Upvotes: 3