New XMLHttpRequest in IE9 raises JScript runtime error: object does not support this property or method

happens only in IE9 (it works fine in firefox) tried to reduce security settings to a minimum. I am not sure about other versions of IE because I have 9 installed.

Environment: asp.net 3.5 web forms scripting: Anthem.NET, jquery

the anthem script is trying to create an instance of XMLHttpRequest and not execute, I tried just creating it myself on the page and had the same error. in the same project, I created a new html page and it worked perfectly.

so it could be some kind of collusion of scripts ...

Is anyone

Here is the source code that fails (line 3), taken from the Anthem.NET framework that runs on the system:

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 value of Window.XMLHttpRequest: enter image description here

and here is the picture of failure that I created myself: enter image description here

Update: Just found out that it works in compatibility mode! and when I return to normal mode, it works again! BTW: document mode is in Quirks mode (default)

+4
source share
3 answers

I recently ran into a problem, and found that if I put code that creates XMLHttpRequest inside a function that runs after the window loads, it works fine every time. Try posting your code:

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

Or if you use jquery:

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

In IE (<v.9) window#XMLHttpRequest is undefined , as it is a global Object for the browser (i.e. for compatible W3C browsers, such as Mozilla or Webkit-based browsers, as well as Opera).

I really don't understand why

 if(window.XMLHttpRequest) 

doesn't evaluate to false , but you can't do anything there.

However, you can add a code plug to it to check window#ActiveXObject (i.e. 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 change the source code at this stage, and the problem persists, you may want to change the scope.


Change I just noticed that you said that the problem occurs in IE 9. In fact, this is not the case, since IE 9 supports the XMLHttpRequest Object .

+1
source

Believe it or not, i.e. DOES NOT actually support XMLHttpRequest (you can change some parameters in your Internet options as an end user, but I'm sure this will not be an acceptable answer to your boss).

For ie9 you have to do this:

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

Then, where will you usually apply (for regular browsers):

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

You will need to do this instead (for ie9):

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

Source: https://habr.com/ru/post/1387012/


All Articles