$.ajax ({
Async:false,
URL: ',//cross-domain URL
Type: ' GET ',
DataType: ' Jsonp ',
JSONP: ' Jsoncallback ',//default callback
Data:mydata,//Request data
timeout:5000,
Beforesend:function () {//jsonp mode This method is not triggered. The reason may be that datatype, if specified as Jsonp, is not an AJAX event.
},
Success:function (JSON) {//client jquery pre-defined callback function, after successfully acquiring JSON data on a cross-domain server, this callback function is executed dynamically
if (json.actionerrors.length!=0) {
alert (json.actionerrors);
}
},
Complete:function (XMLHttpRequest, Textstatus) {
},
Error:function (XHR) {
Jsonp mode This method is not triggered
Request Error Handling
Alert ("Request error (Please check correlation network status.)");
}
});
Copy CodeThe code is as follows:
$.getjson (url+ "? callback=?",
function (JSON) {
});
This is actually an advanced package of the example $.ajax ({.}).
On the server side by obtaining the callback parameter (for example: jsonp*****) to get the jquery end to callback later
It then returns a similar: "jsonp***** (" + JSON array to return + ")";
jquery will invoke this by using the callback method to dynamically load: jsonp***** (JSON array);
This achieves the purpose of cross-domain data exchange.
JSONP is a script injection (scripts injection) behavior, so there are some security implications.
Implementation method of cross-domain access using JSONP under jquery