A previous blog detailed the jsonp protocol. jqueryajax encapsulates the jsonp Protocol to make cross-origin request implementation so simple: $. ajax ({type: & quot; post & quot ;,
A previous blog detailed the jsonp protocol. jquery ajax encapsulates the jsonp Protocol, making cross-origin request implementation so simple:
$. Ajax ({type: "post", url: "http://www.phpddt.com/ajax/test", dataType: "jsonp", jsonp: "callback", // to the request handler or page, the parameter name used to obtain the jsonp callback function name (default: callback) jsonpCallback: "success_jsonpCallback", // The Custom jsonp callback function name, the default value is the random function name success: function (json) {alert ('success ') ;}, error: function () automatically generated by jQuery () {alert ('fail ');}});
The server process is as follows:
$ Data = ....... $ callback = $ _ GET ['callback']; echo $ callback. '('. json_encode ($ data ). ')'; exit;
When jsonp is used and JSONP is used to call a function, for example, "myurl? Callback =? "Will jQuery be replaced automatically? For the correct function name to execute the callback function.