I am trying to make an ajax call to the googlesuggest page that generates a xml. I use a small hack that seems to work and is documented here The code is this:
$.ajax({
url: 'https://suggestqueries.google.com/complete/search',
data: {
client: 'firefox',
q: word,
},
dataType: 'jsonp'
})
.done(function(dataWeGotViaJsonp){
var len = dataWeGotViaJsonp.length;
for(var i=0;i<len;i++){
alert(dataWeGotViaJsonp[i]);
}
});
I don't get any errors in the console on my extension but it doesn't generate anything. How should i make it work properly or what's wrong with it?
The data returned from this: looks like this:
["ob",["obama","obamacare","obituaries","obey","oblivion","obama phone","oberlin college","obama gun control","obagi","obsidian"]]
Where "ob" is the searched term.
Update:
This is the code i updated replacing the $.ajax with $.getJSON after the instructions from the first link i provided in this post.
function process(word){
$.getJSON("https://suggestqueries.google.com/complete/search?callback=?",
{
"jsonp":"suggestCallBack", // jsonp callback function name
"q":word, // query term
"client":"firefox" // force youtube style response, i.e. jsonp
}
);
suggestCallBack= function(dataWeGotViaJsonp){
alert("asdas");
var len = dataWeGotViaJsonp.length;
for(var i=0;i<len;i++){
alert(dataWeGotViaJsonp[i]);
}
};
};
Update 2:
I replaced the keyword 'firefox' under client: specifier with 'youtube' and it now returns something like this:
window.google.ac.h
(
["ob",[["obama",0,[]],
["obamacare",0,[]],
["obituaries",0,[]],
["obey",0,[]],
["oblivion",0,[]],
["obama phone",0,[]],
["oberlin college",0,[]],
["obama gun control",0,[]],
["obagi",0,[]],
["obsidian",0,[]]],
{"k":1,"q":"I3uqQqdI9GsurIoEbRJwRQ_P7Co"}]
)
Which i don't know how to actually parse. I am curious why it is not working under the standard google search. A very good tool for testing purposes can be found on this JSfiddle .