Home > Web Front-end > JS Tutorial > body text

js implements cross-domain requests

小云云
Release: 2018-03-28 15:49:31
Original
1322 people have browsed it

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'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!