Search code examples
autocompletescriptaculousautosuggest

Google suggest queries with Scriptaculous Autocompleter?


I'm trying to display Google suggested queries when a user types in a query into our search text field. Our goal is to combine Google suggested queries with the Scriptaculous Autocompleter.

Here's our code:

new Ajax.Autocompleter('q', 'autocomplete_choices', 'http://suggestqueries.google.com/complete/search?q=test', {method:'get', onSuccess:format_autocomplete});

Fetching http: //suggestqueries.google.com/complete/search?q=test from a browser and from curl works fine and displays the queries suggested for a given string.

However, the responseText in my onSuccess callback always shows the empty string ("") instead of the suggested queries.

Any clues?


Solution

  • Found the answer here: http://jimbojw.com/wiki/index.php?title=What_Would_Google_Suggest%3F

    Briefly, the problem stems from security restrictions on cross-domain AJAX requests. The workaround is on-demand Javascript or Javascript on-demand (JoD).

    Cheers!