The code for the AJAX request data:
$ (function () {
$.ajax ({
url:url,//the URL where the request file resides
Type: "Get",//Request the way
Success:function (data) {
Console.log (data);//Return
}
})
})
The requested data is generally available, but sometimes the so-called cross-domain request problem occurs when requesting data from this domain name to another domain name.
Browsers are enabled by default on the same-origin policy, which refers to the AJAX request page and the requested page in the protocol, domain name, port are the same to be accessed , otherwise the following error will be prompted:
XMLHttpRequest cannot load xxxxxxx is not allowed by Access-control-allow-origin.
So how to solve this problem, jquery provides cross-domain request resolution;
The code is:
$(function() {
$. Ajax ({
URL:URL,//URL where the requested file resides
type:"Get",//method of request,
DataType:"Jsonp",//format of data
Jsonp:"Callback",
Success:function(data) {
Console.Log(data);//Data returned
}
})
})
or by:
Jquery.getjson ("url",(Result) {
console. Log (result);//Return results
})
If a script is requested, the value of the DataType property is changed to "script" when using the method above, or when the following method is used;
Jquery.getscript ("url",(Result) {
console. Log (result);//Return results
});
jsonp:"Callback",
On AJAX requests and cross-domain requests in jquery