What is homology

Source = Protocol + domain name + port number

Two urls are homologous if they have exactly the same protocol, domain name, and port number

What is cross-domain

When a user requests resources of another domain name from the web page of one domain name, the domain name, port, or protocol are all different.

The json cross-domain

When we cross domains, we have to use another way to cross domains because the current browser does not support CORS (usually the poor ones who need to be compatible with IE)

So we request a JS file that will execute a callback with our data in it. The name of the callback can be randomly generated and passed to the background as a callback. The background will return the function to us again and execute it

Advantages: The biggest advantage is compatible with IE, cross – domain

Disadvantages:

  • Since it’s a script tag, it doesn’t read ajax’s exact status code, nor does it know the response headers, so it can only listen for success or failure with onload and onError.
  • Since it is a script tag, only GET requests can be sent. Post is not supported

CORS cross-domain

By default, browsers cannot access data from different sources (to protect user privacy)

But if you really want the two sites to visit each other, you need CORS

How to do?

Just write the site you want to allow in the response header of the resource being accessed

Access-Control-Allow-Origin: foo.example
Copy the code

Perfect solution in one sentence

Disadvantages:

It is not compatible with IE, so IE will use JSONP