homologous

  • The source

Window.org in or location.orgin to get the current source

Source = Protocol + domain name + port number

  • If the protocol, domain name, and port number of two urls are identical, the two urls are homologous

  • For example,

Qq.com, https://www.baidu…. Different source

Baidu.com, https://www.baidu…. Different source

Identical is homologous

Cross domain

When the protocol, domain name, or port of a URL request is different from the current page URL, it is called cross-domain

The same origin policy is restricted by the browser. The same origin policy is a convention. It is the core and most basic security function of the browser. If the same origin policy is absent, the normal functions of the browser may be affected. The Web is built on the same origin policy, and browsers are just an implementation of the same origin policy. The same origin policy prevents javascript scripts in one domain from interacting with content in another domain. Same-origin (that is, in the same domain) means that two pages have the same protocol, host, and port.

CORS

If BBt.com wants to obtain bbter.com data for access to shared data, it must declare it in the BBter.com response header

Access-Control-Allow-Origin:bbt.com

CORS can be divided into simple requests and complex requests. For details, please refer to the MDN document developer.mozilla.org/zh-CN/docs/…

JSONP

JSONP is when we cross domains because the current browser doesn’t support CORS or some condition doesn’t support CORS and we have to use another way to cross domains, so we ask for a JS file, and that JS file will perform a callback and the callback will have our data in it. The callback name can be a random number that we pass to the background as a callback argument, and the background will return the function to us again and execute it.

  • Advantages:

Compatible with IE, can cross domain

  • Disadvantages:

Because it’s a Script tag he can’t read the exact state of AJAX so he doesn’t know what the status code is, he doesn’t know what the entire response header is anything but success or failure because it’s a Script tag it doesn’t support POST it only supports GET requests, okay