JavaScript cross-domain

Source: Internet
Author: User
Tags php write

What is cross-domain?

Why do browsers want to restrict cross-domain?

The above questions are described in more detail and not described in the relevant blog.

What problems have been brought about?

I again 8097 Port want to access 8090 of static resources (fonts or CSS, etc.) is forbidden.

How to solve these problems?

1, Jsonp method, in fact, is the <script> tag src http request to get JSON format data, and then use JavaScript function for processing.

HTTPS://www.cnblogs.com/2050/p/3191744.html

In the Baidu Encyclopedia also said is also very detailed

HTTPS://baike.baidu.com/item/jsonp/493658

Note: The above JSONP if you want to direct $.ajax ({URL:}) that is XMLHttpRequest object to get data from other domains is not possible, this is called prohibit cross-domain. (Of course, this forbidden action is done by the browser)

2, the second method, is to tell the browser this domain name can be cross-domain,

CORS(Cross-Origin Resource SharingThe main use of this, that is, through the HTTP header server to communicate with the browser,

Server-side CORS support, mainly through the setup Access-Control-Allow-Origin to do. If the browser detects the appropriate settings, it can allow Ajax for cross-domain access.

Header ("access-control-allow-origin: *");

Do not know why in the project entrance file index.php write this useless, the browser still give you banned

Related reading recommendations:

HTTPS://www.cnblogs.com/yongshaoye/p/7423881.html

JavaScript cross-domain

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.