Problems and solutions of ajax cross-domain requests

Reasons for cross-domain:

1. URLs are inconsistent

2. The port is inconsistent;

3. The agreement is inconsistent;

Solution:

1. Add the Access-Control-Allow-Origin attribute to the header;

2. Use the jsonp data type;

3. Obtain by proxy.


The first point above will destroy the security policy of the browser, and it is not recommended to do this for sensitive data; the second point can only use the GET method, and the length of the obtained data is limited;

It is recommended to use the third type, that is, proxy, which can not only ensure security, but also allow normal access.

Guess you like

Origin blog.csdn.net/CUG_ZG/article/details/79715225