I always have problems with jQuery UI, and so I do now. I want to use it’s autocomplete feature, so I wrote a little results page which returns JSON response like this:
[ { "value": "2", "label": "Baldur's Gate" }, { "value": "3", "label": "Baldur's Gate 2" }, ];
And my JS is:
function extractLast(term) {
//return split( term ).pop();
var t = term.replace(' ', '%20');
return t;
}
$('nav#mainMenu input').autocomplete({
minLength:3,
source: function(request, response) {
$.getJSON('/Symfony/web/app_dev.php/search/g/' + extractLast(request['term']), response);
}
});
As you see, it’s pretty basic and I think I forgot about something quite obvious, but yet I can’t see what could that be. Any ideas?
Okay, I finally made it 😉
The problem was the data returned to jQuery. I succeeded by using
json_encodewith my array. Here’s the code: