Javascript cross-origin solution (1)

Source: Internet
Author: User
1. Shenma is a cross-domain (CrossDomain). The white point is post, and the get url is not your current website. The domain name is different. For example, in aaa.com/a.html, the table Ticket delivery action is bbb.com/ B .html. In addition, www.aaa.com and aaa.com are also cross-domain, because www... S

 

1. Shenma is a Cross-Domain)

The white point is that the post and get URLs are not your current website, and the domain names are different. For example, in aaa.com/a.html, the table Ticket delivery action is bbb.com/ B .html.

In addition, www.aaa.com and aaa.com are also cross-domain because www.aaa.com is a second-level domain name and aaa.com is a root domain name.

For security reasons, JavaScript does not allow cross-Origin calls to objects on other pages (Same-Origin Policy ).

For a detailed description of whether JavaScript can communicate across regions, see the following table:

Http://www.a.com/a.jsAccess the following URL results

URL Description Allow communication?
Http://www.a.com/ B .js Under the same domain name Allow
Http://www.a.com/script/ B .js Different folders under the same domain name Allow
Http://www.a.com: 8000/B. js Different ports for the same domain name Not Allowed
Https://www.a.com/ B .js Different protocols for the same domain name Not Allowed
Http: // 70.32.92.74/B. js Corresponding ip addresses of domain names and domain names Not Allowed
Http://script.a.com/ B .js The primary domain is the same and the subdomain is different. Not Allowed
Http://a.com/ B .js Same domain name, different second-level domain names (same as above) Not Allowed
Http://www. B .com/ B .js Different domain names Not Allowed

 

2. Why cross-origin?

Cross-origin is actually very common. For example, we can place some scripts, images, or other resources of a website on another site. For example, we can use jQuery provided by Google, which reduces loading time and server traffic, as shown below:

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.