Server-side configuration Implementation Ajax cross-domain request _ajax related

Source: Internet
Author: User

It has always been thought that Ajax Cross-domain is an insurmountable chasm, and recently found that it was possible to allow Ajax Cross-domain requests on the server by sending header information.

PHP code example:

Copy Code code as follows:

Header (' access-control-allow-origin:* ');
Header (' Access-control-allow-headers:x-requested-with ');

After testing, the WebKit kernel browser successfully implemented Cross-domain requests.

ie, as always, does not support ~ seems to be only on the mobile side to enjoy this powerful function

Also, it should be noted that the * in the first row configuration allows Cross-domain requests from all referer, and can be configured to a specific domain if you do not want to be fully open. This ensures that only cross-domain requests from a specific domain name can succeed. For example:

Copy Code code as follows:

Header (' access-control-allow-origin:http://www.test.com ');

The second line of configuration is meant to allow asynchronous Ajax requests because asynchronous Ajax automatically sends this header message, and the server generally determines the AJAX request by accepting header information. Typically, the Ajax requests we send are asynchronous.

The above is the implementation of Ajax Cross-domain request, I hope the small partners like.

Related Article

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.