XMLHttpRequest Cross-domain Request Security configuration under ie7+ Browser

Source: Internet
Author: User
Tags json

Note: The version of Firefox 3.5, Chrome 3.0, and Safari 4 is not a problem with XMLHttpRequest.

ie7+ Browser has started to support XMLHttpRequest objects, when using XMLHttpRequest to request files of different sources (pages of different domain names), and whether the browser is enabled security-"Access data source through domain" in the Internet zone. If this option is enabled, all cross-domain pages are accessible, even if the cross-domain page does not have a Access-control-allow-origin response header set. If the "Access data source through the domain" is disabled, the cross-domain page is set to the Access-control-allow-origin response header is * and cannot be requested, and an error occurs when open.


Note: If you double-click to run or drag into Internet Explorer, the XMLHttpRequest object cannot request local resources, there will be an " Access denied " error, ActiveXObject created objects are not limited, specific reference: the site is not published, What are the local resources that Ajax can request.


<script>
/*var xdr=new XMLHttpRequest ();
Xdr.open ("Get", ' 11.txt ', true); Local test accesses local resource with Access denied error
Xdr.open ("Post", ' http://www.coding123.net/json.asp ', true); If the "Access data source through the domain" is disabled, the cross-domain page is set to the Access-control-allow-origin response header is * and cannot be requested, and an error occurs when open.
Xdr.onreadystatechange = function () {
if (xdr.readystate = = 4) alert (Xdr.responsetext)
}
Xdr.send (NULL) */
</script>


If security is not enabled-the "Access data source through domain" in the Internet zone, the cross-domain page has a access-control-allow-origin response header that allows page requests of all different sources, ie how to request such pages to get the content of cross-domain pages. You can use IE's proprietary Xdomainrequest object.

<script>
var xdr = new Xdomainrequest ();
Note the Xdomainrequest object local browse (double-click or drag-and-drop) cannot request a cross-domain page, or "Deny access." ”,
Web sites need to be published, and cross-domain requests support only http://and https://2 protocols.
Cross-domain pages to be set over Access-control-allow-origin response header is *, no response, no error.
Xdr.open ("Post", ' http://www.coding123.net/json.asp ');
Xdr.onload = function () {
Alert (Xdr.responsetext)
}
Xdr.send (NULL);
</script>


Http://www.coding123.net/article/20130813/IE-XMLHttpRequest-cros-request-safe-config.aspx


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.