JS cross-domainJavaScript is not allowed to call objects on other pages across domains for security reasons.
What is cross domain?
The simple understanding is because the JavaScript homologous policy restriction, the a.com domain name JS cannot operate B.Com or the c.a.com domain name under the object. such as: www.aseoe.com/index.html call www.aseoe.com/service.php (non-cross-domain) www.aseoe.com/index.html call www.ancto.net/service.php ( Cross-domain) www.aseoe.com/index.html call bbs.aseoe.com/service.php (cross-domain) www.aseoe.com/index.html call www.aseoe.com:81/ service.php (cross-domain) www.aseoe.com/index.html call https://www.aseoe.com/service.php (Cross-domain)
Handling Cross-domain Methods One-agent
Create a proxy by using a Web server with the same name: Aseoe server (domain name: www.aseoe.com) ancto server (domain name: www.ancto.net) For example, in the background of a Aseoe Web server (www.aseoe.com/ proxy-anctoservice.php) to invoke the service of the Ancto server (www.ancto.net/service.php) and then return the response result to the front end, In this way, the front-end call Aseoe service with domain name and Ancto service effect is the same
handling Cross-domain Method two-jsonp
Jsonp can be used to solve the problem of Cross-domain data access for mainstream browsers. In www.aseoe.com page: <script> function Jsonp (JSON) {alert (json["name");} </script> <script src= "http:// Www.ancto.net/jsonp.js "></script> on www.ancto.net page: Jsonp ({' name ': Aseoe, ' job ': ' Front end '}); JSONP does not support post requests
Handling Cross-domain Methods three-XHR2
The XMLHttpRequest Level2 provided by HTML5 has enabled Cross-domain access and some other new features IE10 the following versions do not support small modifications to the server: header (' Access-control-allow-origin :*'); Header (' Access-control-allow-methods:post,get ');