cross-domain error: xmlhttprequest cannot load ' url '. No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' URL ' is therefore not allowed access.
What is cross-domain: protocol, subdomain, primary domain, port number, any one of which is not the same, counted as cross-domain.
Cause: JS is not allowed to invoke objects of other pages across domains for security reasons. (same-Origin policy limit)
Workaround:
1. Agent: by creating a proxy on the Web server side of the same domain name
Own:http://www.abc.com
Others ':http://www.bcd.com
When you access your own server (http://www.abc.com/proxy-service.php), your own server (http://www.abc.com/proxy-service.php) calls someone else's service ( http://www.bcd.com/service.php) so that the front-end calls its own server, which is equivalent to calling someone else's server.
2, JSONP: (JSONP cross-domain request support GET request)
Jsonp can be used to address cross-domain data access issues in mainstream browsers:
The server JS file to load the cross-domain JS file, cross-domain JS file return JSONP, is to avoid cross-domain problems.
Front-end Code: $.ajax ({ type: "Get", //Use JSONP cross-domain request only support GET request URL: "Cross domain Address", dataType: "Jsonp", Jsonp: " Callback ", success:function () { if (data.sueccess) { //parse Jsonp }else{ } }, error: function (JQXHR) { Console.log ("Error occurred:" +jqxhr.status);
3, XHR2:
The XMLHttpRequest Level2 provided by HTML5 has implemented cross-domain access and a number of other new features
IE10 versions below are not supported
• Make some minor changes on the server side: (PHP)
Header (' access-control-allow-origin:* ');
Header (' Access-control-allow-methods:post,get ');
JS-cross-domain