jQuery Autocomplete Json Ajax cross browser issue with Google Search Appliance
Posted
by skyfoot
on Stack Overflow
See other posts from Stack Overflow
or by skyfoot
Published on 2010-04-01T11:02:43Z
Indexed on
2010/04/06
11:53 UTC
Read the original article
Hit count: 443
I am implementing a jquery autocomplete on a search form and am getting the suggestions from the Google Search Appliance Autocomple suggestions service which returns a result set in json.
What I am trying to do is go off to the GSA to get suggestions when the user types something in the search box.
The url to get the json suggestions is as follows:
http://gsaurl/suggest?q=<query>&max=10&site=default_site&client=default_frontend&access=p&format=rich
The json which is returned is as follows:
{ "query":"re", "results": [ {"name":"red", "type":"suggest"}, {"name":"read", "type":"suggest"}] }
The jQuery autocomplete code is as follows:
$(#q).autocomplete(searchUrl, {
width: 320,
dataType: 'json',
highlight: false,
scroll: true,
scrollHeight: 300,
parse: function(data) {
var array = new Array();
for(var i=0;i<data.results.length;i++)
{
array[i] = { data: data.results[i], value: data.results[i].name, result: data.results[i].name };
}
return array;
},
formatItem: function(row) {
return row.name;
}
});
This works in IE but fails in firefox as the data returned in the parse function is null. Any ideas why this would be the case?
Workaround I created an aspx page to call the GSA suggest service and to return the json from the suggest service. Using this page as a proxy and setting it as the url in the jQuery autocomplete worked in both IE and FireFox.
© Stack Overflow or respective owner