Reputation: 4212
I have this code :
$(document).ready(function(){
$("#search_input").autocomplete({
source: function(request, response) {
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql',
dataType: 'JSONP',
data: {
format: 'json',
q: 'select * from xml where url="http://google.com/complete/search?hl=nl&output=toolbar&q=' + encodeURIComponent(request.term) + '"'
},
success: function(data) {
response($.map(data.query.results.toplevel.CompleteSuggestion, function(item) {
return { label: item.suggestion.data, value: item.suggestion.data };
}));
}
});
}
});
});
For some reason it doesn't work with Jquery 1.4 but it does with 1.7 Is this becouse JSONP was not introduced with 1.4? How can I make it work with 1.4? Here is the Fiddle JsFiddle
Upvotes: 0
Views: 344
Reputation: 349062
You've got two problems:
jQuery ____
at Use Choose framework
, The critical part of your code is caused by jQuery itself:
In jQuery 1.4, the response is a string. To get the code to work in older jQuery versions, add one line to the success
handler:
success: function(data) {
if (typeof data == 'string') data = $.parseJSON(data);
Upvotes: 2