Home > Article > Web Front-end > js implements cross-domain requests
This article mainly shares with you js to implement cross-domain requests, mainly combining text and code. I hope it can help everyone.
1. Install flash and interact with flash to achieve cross-domain, but this method is too troublesome and is rarely used
2.
The second is to use the same source A proxy server is set up under the domain name for forwarding, and JavaScript is responsible for sending the request to the proxy server:
'/proxy?url=http://www.sina.com.cn'
The proxy server then returns the result, thus complying with the browser's same-origin policy. The trouble with this approach is that it requires additional development on the server side.
3. The JSONP method can only use GET requests and is required to return js. Taking advantage of cross-domain, it actually uses the browser's feature of allowing cross-domain js resources to be referenced.
4.cros cross-domain strategy, Origin represents this domain, which is the domain of the current page of the browser. When JavaScript initiates a request to an external domain (such as sina.com), after receiving the response, the browser first checks whether Access-Control-Allow-Origin contains this domain. If so, the cross-domain request is successful. If not, then If the request fails, JavaScript will not be able to obtain any response data. All types of http requests are supported.
Related recommendations:
js cross-domain request service instance analysis
The above is the detailed content of js implements cross-domain requests. For more information, please follow other related articles on the PHP Chinese website!