This article describes how to simulate jsonp in JavaScript. This article provides the implementation code directly. the code contains detailed comments. For more information, see
Function prescript (s) {if (s. cache === undefined) {s. cache = false;} if (s. crossDomain) {s. type = "GET" ;}} function prejsonp (s, originalSettings, jqXHR) {// name var callbackName = s for the callback function. jsonpCallback s. url + = (/(? :)/. Test (s. url )? "&":"? ") + S. jsonp + "=" + callbackName; // after the script is executed, use a data converter to retrieve json. // The data that is provided to the code to obtain the server is s. getData = function () {if (! ResponseContainer) {jQuery. error (callbackName + "was not called");} return responseContainer [0];}; // modify the processing mechanism s. dataTypes [0] = "json"; // create a global function overwritten = window [callbackName]; // used to collect data from the server window [callbackName] = function () {responseContainer = arguments;}; return "script";}/*** jsonp pre-processing */function inspectPrefiltersOrTransportsA (options, originalOptions, jqXHR) {// pre-process jsonp var dataTypeOrTransport = prejsonp (options, originalOptions, jqXHR) // expand dataTypes options. dataTypes. unshift (dataTypeOrTransport); // pre-processing script type prescript (options)}/*** distributor * @ return {[type]} [description] */function inspectPrefiltersOrTransportsB (s, originalOptions, jqXHR) {return {send: function (_, complete) {var script = jQuery ("script"). prop ({async: true, charset: s. scriptCharset, src: s. url }). on ("load error", callback = function (evt) {script. remove (); callback = null; if (evt) {complete ()}});//