简体   繁体   English

IE9中的新XMLHttpRequest导致JScript运行时错误:对象不支持此属性或方法

[英]new XMLHttpRequest in IE9 causes a JScript runtime error: Object doesn't support this property or method

happens only in IE9 (in firefox it works fine) tried lowering the security settings to minimum. 仅在IE9中发生(在Firefox中它工作正常)尝试将安全设置降至最低。 i'm not sure about other versions of IE because i have 9 installed. 我不确定IE的其他版本,因为我安装了9。

Environment: asp.net 3.5 webforms scripting frameworks: Anthem.NET, jquery 环境:asp.net 3.5 webforms脚本框架:Anthem.NET,jquery

the anthem script is trying to create an instance of XMLHttpRequest and fails i tried just create it myself on the page and had the same error. anthem脚本试图创建XMLHttpRequest的实例并且失败我尝试在页面上自己创建它并且有相同的错误。 on the same project i've created a new html page and it worked fine. 在同一个项目中,我创建了一个新的html页面,它工作正常。

so it might be some scripting collusion... 所以它可能是一些脚本勾结......

Anyone? 任何人?

Here is the original code that fails (on line 3) taken from the Anthem.NET framework that runs on the system: 以下是从系统上运行的Anthem.NET框架中获取的原始代码(第3行):

function Anthem_GetXMLHttpRequest() {
if (window.XMLHttpRequest) {  // <-- This passes as True! window.XMLHttpRequest is {...}
    return new XMLHttpRequest(); // <---- Fails here
} else {
    if (window.Anthem_XMLHttpRequestProgID) {
        return new ActiveXObject(window.Anthem_XMLHttpRequestProgID);
    } else {
        var progIDs = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
        for (var i = 0; i < progIDs.length; ++i) {
            var progID = progIDs[i];
            try {
                var x = new ActiveXObject(progID);
                window.Anthem_XMLHttpRequestProgID = progID;
                return x;
            } catch (e) {
            }
        }
    }
}
return null;

} }

here's the Window.XMLHttpRequest value: 这是Window.XMLHttpRequest值: 在此输入图像描述

and here is a picture of the failure that i created myself: 这是我自己创造的失败的图片: 在此输入图像描述

Update: Just found out that it works in Compatibility Mode ! 更新:刚刚发现它在兼容模式下工作! and when i go back to normal mode it works again! 当我回到正常模式时,它再次起作用! BTW: the document mode is on Quirks mode (which is the default) BTW:文档模式处于Quirks模式(这是默认模式)

Recently I ran into the problem and I found that if I place the code which creates the XMLHttpRequest inside of a function that runs once the window loads that it works fine every time. 最近我遇到了问题,我发现如果我将一个创建XMLHttpRequest的代码放在一个窗口加载运行的函数内,每次都可以正常工作。 Try placing your code in this: 尝试将代码放入:

window.onload = function() {
    var lala = new XMLHttpRequest();
}

Or if you use jquery: 或者如果你使用jquery:

$(function() {
    var lala = new XMLHttpRequest();
});

Believe it or not, ie9 DOES NOT actually support XMLHttpRequest (you can change some settings in your internet options as the end-user, but I'm sure that's not gonna be an acceptable answer to your boss). 信不信由你,ie9实际上并不支持XMLHttpRequest(你可以改变你的互联网选项中的一些设置作为最终用户,但我确信这对你的老板来说不会是一个可接受的答案)。

For ie9, you gotta do this: 对于ie9,你必须这样做:

var xmlhttp;
if (ie9)
{
    xmlhttp=new XDomainRequest();
}
else
{
    xmlhttp=new XMLHttpRequest();
}

Then, where you'll normally apply (for regular browsers): 然后,您通常会申请(对于常规浏览器):

xmlhttp.onreadystatechange=function()
{
     if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
          // do your thing
     }
};

You'll have to do this instead (for ie9): 你必须这样做(对于ie9):

if (this.ie9)
{
     xmlhttp.onload = function()
     {
         // do your ie9 thing
     };
}

In IE (< v.9 ) window#XMLHttpRequest is undefined as this is a browser specific global Object (ie for W3C conformant browsers such as the Mozilla or Webkit based browsers as well as Opera). 在IE(<v.9) window#XMLHttpRequest undefined因为这是一个特定于浏览器的全局Object (即对于符合W3C标准的浏览器,例如基于Mozilla或Webkit的浏览器以及Opera)。

I don't really understand myself why 我真的不明白自己为什么

if(window.XMLHttpRequest)

does not evaluate to false but well nothing you can do there. 不评价为false但没有什么可以做到那里。

What you can do however is add a code fork before that to check for window#ActiveXObject (ie Internet Explorer) 然而,你可以做的是在此之前添加一个代码叉来检查window#ActiveXObject (即Internet Explorer)

if(!! window.ActiveXObject) { // same as typeof window.ActiveXObject !== "undefined"
    /* use MSXML */
}
else if(!! window.XMLHttpRequest) {
    /* use XMLHttpRequest */
}
else throw Error("Browser does not support XHR.") ;

If you cannot modify the source code at this point and the problem persists you might want want to change frameworks. 如果此时无法修改源代码并且问题仍然存在,则可能需要更改框架。


Edit : I just now noticed that you were saying the problem shows up in IE 9. That should actually not be the case as IE 9 supports the XMLHttpRequest Object . 编辑 :我刚刚注意到你说这个问题出现在IE 9中。实际情况并非如此,因为IE 9支持XMLHttpRequest Object

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft JScript运行时错误:对象不支持IE9中的属性或方法&#39;getElementsByTagName&#39; - Microsoft JScript runtime error: Object doesn't support property or method 'getElementsByTagName' in IE9 IE9中的Jquery 2.1.1得到错误:0x800a01b6-Microsoft JScript运行时错误:对象不支持属性或方法&#39;addEventListener&#39; - Jquery 2.1.1 in IE9 get error: 0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'addEventListener' Microsoft JScript运行时错误:对象不支持此属性或方法 - Microsoft JScript runtime error: Object doesn't support this property or method Microsoft JScript运行时错误对象不支持此属性或方法 - Microsoft JScript runtime error Object doesn't support this property or method IE9错误:对象不支持属性或方法“ setAttribute” - IE9 error: Object doesn't support property or method 'setAttribute' FullCalendar错误-Microsoft JScript运行时错误:对象不支持此属性或方法 - FullCalendar error - Microsoft JScript runtime error: Object doesn't support this property or method 出现js错误:Microsoft JScript运行时错误:对象不支持此属性或方法 - getting the js error : Microsoft JScript runtime error: Object doesn't support this property or method 我们如何清除此错误Microsoft JScript运行时错误:对象不支持属性或方法&#39;querySelectorAll - how can we clear this error Microsoft JScript runtime error: Object doesn't support property or method 'querySelectorAll Microsoft JScript运行时错误:对象不支持属性或方法&#39;__defineGetter__ - Microsoft JScript runtime error: Object doesn't support property or method '__defineGetter__ Microsoft JScript 运行时错误:对象不支持属性或方法“datepicker” - Microsoft JScript runtime error: Object doesn't support property or method 'datepicker'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM