IE 8 安全设置阻止 javascript 发送 xmlHTTPRequest

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7964478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:53:05  来源:igfitidea点击:

IE 8 security settings prevents javascript to send xmlHTTPRequest

javascriptsecurityinternet-explorer-8xmlhttprequest

提问by Ved

I am facing problem that whenever I turn off security settings in IE8, in my application, xmlHTTPRequest call is failed.However when I turn it on, its working fine. The security feature is : Tools -> Internet Options -> Advance -> security -> Enable Native xmlHTTP support. If it is checked then no problem occurs but in case if it is not checked, the xmlHTTPReq fails to send request to server.(I don't see the cgi call in debugger window).

我面临的问题是,每当我关闭 IE8 中的安全设置时,在我的应用程序中,xmlHTTPRequest 调用失败。但是,当我打开它时,它工作正常。安全功能是:工具 -> Internet 选项 -> 高级 -> 安全 -> 启用原生 xmlHTTP 支持。如果选中,则不会出现问题,但如果未选中,则 xmlHTTPReq 无法将请求发送到服务器。(我在调试器窗口中没有看到 cgi 调用)。

So my question is : is it possible to detect that this security settings is enabled or not using JavaScript programatically ?

所以我的问题是:是否可以通过编程方式检测到此安全设置是否启用或未使用 JavaScript?

My code for cgi call is as under :

我的 cgi 调用代码如下:

try{
        var xmlHttpReq;
        var destinationURL = cgiBinPath+"helloworld.cgi?start";
        // IE 7+, Mozilla/Safari
        if (window.XMLHttpRequest) {
            xmlHttpReq=new XMLHttpRequest();
        }
        //IE 5,6
        else {
            xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (xmlHttpReq.readyState == 0){
            xmlHttpReq.open('GET', destinationURL, true);
            xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlHttpReq.onreadystatechange = function(){
                if(xmlHttpReq.readyState == 4){
                  //Control never reaches here
                }
            }               
            xmlHttpReq.send();
        }
    }catch(e){
        alert('Exception '+e);
    }  

采纳答案by Andreas

Take a look at thisarticle about native XMLHTTP on MSDN. It also provides a solution for your problem.

在 MSDN 上查看有关本机 XMLHTTP 的这篇文章。它还为您的问题提供了解决方案。

EditI'm sorry, I didn't read the article carefully enough... Thisone will answer your question. You will have to try if you can create an instance of the XMLHttpRequestobject.

编辑对不起,我没有仔细阅读这篇文章...这篇文章将回答您的问题。您将不得不尝试是否可以创建XMLHttpRequest对象的实例。

if (window.XMLHttpRequest) {
    try {
        xmlHttpReq = new XMLHttpRequest();
    } catch (ex) {
        xmlHttpReq = new window.ActiveXObject("Microsoft.XMLHTTP");
    }
} else {
    //...
}