$.ajax({
async:false,
url: '', // Cross-domain URL
type: 'GET',
dataType: 'jsonp',
jsonp: 'jsoncallback', //Default callback
data: mydata, // Request data
timeout: 5000,
beforeSend: function(){ //jsonp method is not triggered. The reason may be that if dataType is specified as jsonp, it is no longer an ajax event.
},
success: function (json) { //The callback function predefined by jquery on the client side. After successfully obtaining the json data on the cross-domain server, this callback function will be dynamically executed
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 the correlation network status.)");
}
});
$.getJSON(url "?callback=?",
function(json){
});
This method is actually the above example A high-level wrapper for $.ajax({..}).
On the server side, get the callback parameter (such as: jsonp*****) to get the subsequent callback on the jQuery side
and then return something like: "jsonp*****(" the json to be returned Array ")";
jquery will dynamically load and call this through the callback method: jsonp*****(json array);
This achieves the purpose of cross-domain data exchange.
JSONP is a kind of script injection (Script Injection) behavior, so it also has certain security risks.
Note: jquey does not support cross-domain posting.
Reference:
http://www.ibm.com/developerworks/cn/web/wa-aj-jsonp1/