Cross-domain resource sharing

Source: Internet
Author: User

1. What is cross-domain resource sharing

CORS (Cross-origin Resource sharing, cross-domain resource sharing) is a site of resources to access another non-homologous site resources, the basic idea is to use a custom HTTP header to the browser and the server to communicate, This determines whether the request or response succeeds or fails.

2. Why use cross-domain resource sharing

Because of the cross-domain security policy restriction, AJAX communication is implemented through XHR, and the XHR object can only access resources that reside in the same domain as the page that contains it. In practical applications, external stylesheet files are loaded via tags, external images are loaded via tags, and/or a JSONP request is

First, the first script note defines a function to process the data;

Then the second script tag loaded into a JS file, http://example.com/data.php is the address of the data, but because it is used as JS to introduce, so the http://example.com/data.php return must be a can execute the JS file;

The last JS file loaded successfully executes the function we specified in the URL parameter, and the JSON data we need is passed as a parameter. So PHP is supposed to be like this

 
     

The output is: Handleresponse ([' A ', ' B ', ' C ']);

JSONP is a server-side page that needs to be matched accordingly.

SSE and Web Ssockets

  • 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.