Search code examples
jsonp

What does JQuery do with randomly generated callback name for JSONP?


so since Ajax generates something like this for the request

callback=jQuery19104342058659531176

and in the end server returns

jQuery19104342058659531176(data)

what does it call if jQuery19104342058659531176() function is (obviously) not defined?

I understand it will go to success/error handler, but dont really get the purpose of the callback then?


Solution

  • in fact, jQuery will invoke the callback, then invoke success/error. If you omit "jsonpCallback", then jQuery will invoke the default one deined by jQuery. the source code is in jsonp.js:

    window[ callbackName ] = function() {
        responseContainer = arguments;
    };