I'm using JQuery to make JSONP requests and the documentation is quite confusing.
I have several questions:
- A JSONP call is always async, is that correct? So the
async:false
would be simply ignored? - If the
jsonpCallback
parameter is specified, this function will be executed when the data are retrieved. But right after, also thesuccess
callback will be executed. Jquery advices NOT to specify thejsonpCallback
function(only for caching?). What is the role of this function in relation with thesuccess
function? - If the
jsonpCallback
is not specified a random callback function will be created and attached to thewindow
object. Something likejQuery1360574548776335413_1776656584447
, what is its role? How does it work? Does it have any relation with thesuccess
function? - Is the
error
callback never called?
Here's my code:
(function($) {
var url = "https://www.googleapis.com/books/v1/volumes/zyTCAlFPjgYC";
$.ajax({
type: 'GET',
url: url,
// JSONP always async?
async: false,
jsonp: "callback",
jsonpCallback: 'jsonCallback',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
console.dir(json);
},
// Error never called?
error: function(e) {
console.log(e.message);
}
});
})(jQuery);
function jsonCallback(json) {
$(".test").html(json.volumeInfo.title);
}
jsonp
actually works behind the scenese if you don't already. en.wikipedia.org/wiki/JSONP – James Montagne