Several ways to achieve cross-domain access by JS

Source: Internet
Author: User
Tags script tag

Different domains: protocol, domain name, port any one different;

1,JSONP cross-domain

In JS, it is not possible for us to use XMLHttpRequest to request data from different domains directly. However, it is really possible to refer to a JS script file on a different domain on the page, and the JSONP is implemented using this feature.

Introduce a JS file through the script tag, this JS file will execute the function we specified in the URL parameter, and will pass in the JSON data we need as parameters. So JSONP is the server side of the page to coordinate the corresponding.

2.document.domain to cross subdomains

3.window.name cross-domain

The newly introduced Window.postmessage method in 4.HTML5 to transfer data across domains

5.flash cross-domain

6. Setting up agents across domains on the server

http://blog.csdn.net/kongjiea/article/details/38867531

Several ways to achieve cross-domain access by JS

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.