i'm using jquery make jsonp requests , documentation quite confusing.
i have several questions:
- a jsonp call async, correct?
async:falseignored? - if
jsonpcallbackparameter specified, function executed when data retrieved. right after,successcallback executed. jquery advices not specifyjsonpcallbackfunction(only caching?). role of function in relationsuccessfunction? - if
jsonpcallbacknot specified random callback function created , attachedwindowobject.jquery1360574548776335413_1776656584447, role? how work? have relationsuccessfunction? - is
errorcallback never called?
here's code:
(function($) { var url = "https://www.googleapis.com/books/v1/volumes/zytcalfpjgyc"; $.ajax({ type: 'get', url: url, // jsonp 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); }
a jsonp call async, correct? async:false ignored?
that correct
if jsonpcallback parameter specified, function executed when data retrieved. right after, success callback executed. jquery advices not specify jsonpcallback function(only caching?). role of function in relation success function?
the success function callback. jquery generates random function name usually. if, however, you're making several of same requests , instead allow browser cache calls, can specify function randomly generated 1 not created. inspect network requests , you'll see (as long server set support it) if specify name, should
304 - not modified(edit: on subsequent requests after first), while other calls return200 ok
if jsonpcallback not specified random callback function created , attached window object. jquery1360574548776335413_1776656584447, role? how work? have relation success function? error callback never called?
that callback function should contain code put in success. error event fired if there error actual request, such invalid domain name, 401 server response, , etc.
Comments
Post a Comment