I can't understand the doc of the jQuery.ajax, specifically two options: jsonp
and jsonpCallback
, so can somebody be so pleasant to explain?
What I do understand is that jsonp
is a name of a GET parameter which server expects (usually 'callback') and jsonpCallback
is a name of a function to wrap a response. Seems simple.
But the explanation at the jQuery.ajax doc makes this a bit complicated. I would like to cite the complete text for jsonp
option here and mark with bold what is obscure to me:
jsonp
Override the callback function name in a jsonp request. This value will be used instead of 'callback' in the 'callback=?' part of the query string in the url. So {jsonp:'onJSONPLoad'} would result in 'onJSONPLoad=?' passed to the server. As of jQuery 1.5, setting the jsonp option to false prevents jQuery from adding the "?callback" string to the URL or attempting to use "=?" for transformation. In this case, you should also explicitly set the jsonpCallback setting. For example, { jsonp: false, jsonpCallback: "callbackName" }
So the questions are:
1.What does it mean "=?" or 'callback=?' (extra question mark)? When I perform a JSONP AJAX-request like here:
$.ajax('http://fake.com',{
dataType: 'jsonp',
success: function(data) {console.log(data);}
});
The URL looks like this, there is no such question mark:
http://fake.com/?callback=jQuery18104830878316494931_1352981996209&_=1352981999411
2.What is the extra parameter (underscore) _=1352981999411
?
3.What do the words In this case, you should also explicitly set the jsonpCallback setting
mean? I can't see any interrelationship. If I set { jsonp: false, jsonpCallback: "callbackName" }
, as it is said in the doc the query will look like this:
http://fake.com/?_=1352981999411
There is no use of the "callbackName" at all so why to specify it?
My appreciation.
callback=X
orcallback=YOUR-CALLBACK