Workaround for a cross-site XMLHTTP request

Source: Internet
Author: User
Tags call back functions net access
xml| Resolution | request | site users after the latest patch of IE, ie default configuration, the use of XMLHttp will not be able to access across the site, such as the http://community.csdn.net/page can not access http:// message.csdn.net/the page. The following error will be reported:

---------------------------
Error
---------------------------
A run time error occurred.
Do you want to debug?

Line: 49
Error: Access denied.
---------------------------
Yes (Y) No (N)
---------------------------

One way to fix this:
Principle, use the following way to invoke a script that is available across a Web site:
<script id=message language=javascript src= "******************" ></script>

As a then, we can implement a cross-site scripting call in the following code format. In turn, the implementation of XMLHttp can not be called across the site.

var Url = "http://message.csdn.net/********":
var scriptname = "Checkuserhasnewmessage";

var head= document.getelementsbytagname ("Head"). Item (0);
var old = document.getElementById (scriptname);
if (old) head.removechild (old);

var script = document.createelement ("script");
SCRIPT.SRC = URL;
Script.defer = true;
Script.type = "Text/javascript";
Script.id = ScriptName;
Head.appendchild (script);

This script requires the callee to return the JS script. You can write some functions in advance of the caller and then call back the calls of those functions.
The above methods in the previous version of IE, FireFox default settings are no problem.

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.