im getting response in json (can check in firebug), but this wont parse the json response and no results displayed. what mi doing wrong? i could'nt find anything on doc http://docs.jquery.com/Plugins/Autocomplete
Here is my JSON response
({"Contacts":[{"Phone":"","Email":"","Labels":"","Mobile":"12345678","Firstname":"john"}]});
And This is my jQuery:
$("#destinations").autocomplete({
source: function (request, response) {
$.getJSON("http://localhost/contactApi.do?callback=?",
{ 'contactMobile': request.term, maxRows: 12, style: "full" },
function(data) {
if(data.Contacts){
var x = $.map(data.Contacts, function(v, i){
console.log(v)
return {
label: v.Mobile + ' - ' + v.Firstname,
v: v.Firstname
}
});
response(x);
}
}
);
}
})
It happened to me once that the problem was on the server side. I was sending the response as a raw string instead of JSON. Take a look in firebug if you are able to see the proper headers (content-type:application/json) being sent back from the server. Also you should be able to see a tab named JSON using firebug. After I added the proper headers I was able to deserialize the values using jQuery.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.