Home > Web Front-end > JS Tutorial > Ajax cross-domain methods—jsonp and CROS

Ajax cross-domain methods—jsonp and CROS

高洛峰
Release: 2016-12-14 13:10:07
Original
1272 people have browsed it

In the past, I only knew that the solution to cross-domain ajax could only be solved through jsonp. Recently, when uploading videos locally, I needed to upload the video to Youku and YouTube. If I uploaded it directly through the post method, I could only see the upload at the bottom of the browser. Progress and user experience are very poor. If you use ajax to upload, you can customize the upload progress and display the upload speed. However, since the video is uploaded to a third-party video service provider, the first problem encountered is cross-domain.

CORS can solve this problem.

CORS is undoubtedly more advanced, convenient and reliable than JSONP.
1. JSONP can only implement GET requests, while CORS supports all types of HTTP requests.

2. Using CORS, developers can use ordinary XMLHttpRequest to initiate requests and obtain data, which has better error handling than JSONP.

3. JSONP is mainly supported by old browsers, which often do not support CORS, while most modern browsers already support CORS.

PHP: header(""Access-Control-Allow-Origin: *"");
html:

If CORS contains a 302 jump, the URL after the 302 jump needs to also contain the CORS header request.

Currently, IE8 and above and other mainstream browsers already support CORS cross-domain. I believe this technology will be very practical in the future.




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