What is homology
In simple terms, two urls are of the same origin if their protocols, domain names, and port numbers are identical.
Take a look at the components of the URL:
- http:// – > agreement
- WWW –> subdomain name
- Hahaha.com –> Master domain name
- 80 –> port (http://default port is 80)
- ABC /a.js –> Request resource path
What is cross-domain
If a protocol, subdomain name, main domain name, or port number is different, the domain name is counted as different. Cross-domain means that requests for resources between different domains count as cross-domain.
CORS cross-domain
Under the security protection of the same origin policy, web pages are not allowed to cross domains, and CORS is one of the methods to cross domains.
To enable CORS, simply set access-Control-Allow-Origin on the server. This attribute indicates which domain names can access resources. If a wildcard is set, all websites can access resources.
CORS can be divided into simple and complex requests. For details, please refer to the MDN document developer.mozilla.org/zh-CN/docs/…
The json cross-domain
JSONP is also one of the cross-domain methods, which can be used when CORS methods are not available, such as Internet Explorer cross-domain.
JSONP principle:
Web pages can get JSON data dynamically generated from other sources by taking advantage of the
JSONP implementation:
-
Declare a callback function whose function name (such as XXX) is passed as a parameter value to the server that requests data across domains, and whose function parameter is to fetch the target data (the data returned by the server).
-
Create a
-
The server receives the request: concatenates the function name passed in with the data it needs to give you into a string.
-
Finally, the server returns the data to the client through HTTP protocol. The client then calls the previously declared callback function (XXX) to operate on the returned data.