JavaScript cross-domain problem

Source: Internet
Author: User
Tags end header json net new features domain domain name access
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 ');


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.