I'm trying to add autocomplete to my search input:
jQuery( "#search_word" ).autocomplete({
source: function(request, response) {
$.getJSON("/search/auto-complete", { k: $('#search_word').val() },
response);
},
select: function( event, ui ) {
var item = ui.item;
jQuery(this).val(item.value);
if (item.url) {
window.location.href = item.url;
return false;
}
var page_name = jQuery(this).attr('data-page-name');
submitCategory();
}
});
But as you can probably guess, I couldn't. Some extra fields are returned if they have the same keyword.
I created a fiddle:
Nobody has to fix it for me. I just want to know how can I parse the data and show a response.
The data that my source callback returns looks like this:
{
"keyword": ["zippo","zippo lighter","zippo warmer"],
"store":{
"storeId":44922,
"storeName":"Zippo",
"storeTitle":"Zippo",
"storeLogoUrl":"http://images.server.com/d/store/d_44922.jpg",
"storeSlug":"zippo"
}
}
keyword includes autocomplete options. store isn't always populated. If it is, I want to include storeTitle as the last value in my autocomplete options.
Thanks.