How to solve the cross-domain problem, there are two situations: 1. Cross-domain between a.com and b.com; 2. Cross-domain between test1.a.com and test2.a.com. What is the difference between the two kinds of cross-domains? What is the solution?
There is no difference between the two cross-domains, even different port numbers under the same domain will have the same cross-domain problem. There are many cross-domain solutions, such as jsonp with Padding, cors, etc. cors is generally used. cors is transparent at the front end and does not need to be modified. The browser will automatically send preflight request and need to modify background code. When preflight request response and formal http request response are made, headers such as Access-Control-Allow-Origin, Access-Control-Allow-Methods, etc. are added to the response header. If these headers meet the requirements of CORS, the browser will release the cross-domain request.