Hey, I am doing to AJAX call to "flickr.interestingness.getList" to get the interesting pictures and this is my AJAX call.
function getPhoto()
{
$.ajax("http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&format=json&api_key=fbfe07eb3cc28814df5bbc0313cdd521",
{
dataType: "jsonp",
//jsonp: false, jsonFlickrApi: "jsonpcallback",
jsonpCallback: "jsonFlickrApi",
});
}
function jsonFlickrApi(data)
{
alert(data.photos.photo);
}
and here "JsonFlickrApi" is the pre-defined function from Flickr that wraps the json object which has a bunch of photos. My question is could I somehow override the pre-defined function, "jsonFlickApi" and name the callback function something other than "jsonFlickrApi", I thought the jsonp parameter is supposed to do that after I read the jQuery documentation but just failed to change it.or I dont quite understand what the jsonp parameter does in jQuery AJAX call. thank you
You are close. This works perfectly:
function getPhoto() {
$.ajax({
url: "http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&format=json&api_key=fbfe07eb3cc28814df5bbc0313cdd521",
dataType: "jsonp",
jsonp: 'jsoncallback',
success: function(data) {
alert(data);
}
});
}
getPhoto();
DEMO
As the documentation describes, you can set your own callback name with the jsoncallback parameter. Hence we have to set jsonp: 'jsoncallback'. In the jQuery documentation you can find that it is recommended to let jQuery choose a callback name. Just set the success callback and you are done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With