Internet Explorer 8 and XMLHttpRequest Prototypes

This is partly a request for a workaround, and partly an attempt to get a message stating that the prototype implementation of Internet Explorer is still malfunctioning.

The following code does not work in Internet Explorer.

XMLHttpRequest.prototype.old = XMLHttpRequest.prototype.open;
var x = new XMLHttpRequest();
x.old("POST", "test", false);

For IE 8 beta and all previous versions, the XMLHttpRequest.prototype property never existed in the first place. In IE8, it exists, but you get the error message "Invalid procedure call or argument". Internet Explorer does not like design.

Does anyone know of a workaround for this?

Update

It has been pointed out that I can override the whole XMLHttpRequest with a new function and constructor, and then create a wrapper script ala XMLHttpRequest.js. The prototype method is much shorter, so I would prefer to use it for browsers other than IE.

+3
source share
1 answer

The problem is that IE 8 recognizes XMLHttpRequest, but not as a function. Active X objects still work. Instead of checking for the existence of window.XMLHtppRequest, I am checking the type of window.XMLHtppRequest. seems to be working fine.

I transcoded the receive request as follows:

FG.ajax.getxhr = function(){
var xhr;
if (typeof window.XMLHttpRequest === 'function') {
    xhr  = XMLHttpRequest();
}
else {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xhr; 
+2
source

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


All Articles