1. What is cross-domain
When the same origin policy is violated, cross-domain is created
Cross-domain problems occur between clients and servers, not between servers
2. The same Origin policy (the same origin policy is a security restriction of the browser)
(1) If the domain name, protocol, and port number of two urls are the same, they are called two urls of the same origin.
(2) If the domain name, protocol, and port number of the URL are different, the source is different.
Function: Prevents data leakage caused by cookie sharing between different websites.
3. Categories of requests sent by browsers
Graph TD browser HTTP requests --> Ordinary HTTP requests --> Script /img/link/form tags send requests Browser HTTP requests --> special HTTP requests --> Ajax requests
4. Resolve cross-domain
(1) the json
- Features: Only support GET request - use - create script tag - set callback function - set script SRC property - add body in effectCopy the code
(2) the cors
- Access - Control-allow-origin: * - access- Control-allow-origin: * - Access - Control-allow-origin: http://localhost:5000
- access-control-allow-methods: get, post, put, delete
- access-control-allow-headers: token
- access-control-max-age: 3648000
Copy the code
(3) Server proxy