Cross-origin ajax methods-jsonp and CROS

Source: Internet
Author: User
In the past, we only knew that ajax cross-origin can only be solved through the jsonp method. When uploading a video locally recently, we need to upload the video to Youku and youtube. If we use the post method directly, you can only see the upload progress below the browser, and the user experience is poor. If you use ajax to upload, you can customize the upload progress and display the upload speed. However, due to the upload to a third-party video service provider, the first problem is cross-origin. In the past, we only knew that ajax cross-origin can only be solved through the jsonp method. When uploading a video locally recently, we need to upload the video to Youku and youtube. If we use the post method directly, you can only see the upload progress below the browser, and the user experience is poor. If you use ajax to upload, you can customize the upload progress and display the upload speed. However, due to the upload to a third-party video service provider, the first problem is cross-origin.

CORS can solve this problem.

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

2. With CORS, developers can use common XMLHttpRequest to initiate requests and obtain data, which provides better error handling than JSONP.

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

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

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

Currently, both IE8 and other mainstream browsers support CORS. We believe this technology will be very useful in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.