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