I know this has been asked a zillion times, but I still can\'t get my code to work. I am trying to a simple JSONP call from my Javascript application. The cod fragment loo
Check this out JsFIddleDemo
/*
* create callbak function for jsonP
* @params
* data is response from http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=AAA&callback=myjsonpfunction
*/
function myjsonpfunction(data){
alert(data.responseData.results) //showing results data
$.each(data.responseData.results,function(i,rows){
alert(rows.url); //showing results url
});
}
//request data using jsonP
$(function(){
$.ajax({
url:'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=AAA&callback=myjsonpfunction',
type:"GET",
dataType: 'jsonp',
jsonp: 'myjsonpfunction',
async:'true',
success:function (data) {
//alert("success");
}
});
});
you need write a callback parameter and callback function,the google ajax apis will be return only json if you don't set of callback.
if you set url like this
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=AAA&callback=?(another)
the response is
{"responseData": null, "responseDetails": "bad or missing callback or context", "responseStatus": 400}
Looks like the method you are using is deprecated: https://developers.google.com/web-search/docs/reference
And has moved on to: http://code.google.com/apis/customsearch/v1/overview.html