When we are developing projects, we typically use AJAX to request data, but there are cross-domain issues when using AJAX.
Why is there a cross-domain problem?
Cross-domain problems arise from the same-origin JavaScript policy, which means that access is permitted in the same domain name, protocol name, and port number, meaning that JavaScript only allows access to resource files under its own domain.
How to troubleshoot cross-domain
There are three ways to solve cross-domain:
In writing Ajax is set DATATYPE:JSONP it means to allow the server-side integration scrip tags back to the client, through JavaScript callback form can be solid cross-domain access.
- Only need to fill in the response header on the server side
Header ("access-control-allow-origin:*");/* Asterisks indicate that all domains are acceptable, */
Header ("Access-control-allow-methods:get,post");
- Agent (This method is seen on the Internet, detailed can refer to other blogs)
The processing method of Ajax cross-domain