Crashalot
Crashalot

Reputation: 34513

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?

Upvotes: 1

Views: 2824

Answers (2)

hamczu
hamczu

Reputation: 1774

I think that JSONP is the answer!
jQuery UI autocomplete widget has this feature by deafault

Upvotes: 1

Crashalot
Crashalot

Reputation: 34513

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!

Upvotes: 1

Related Questions