Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I wanted to extend XMLHttpRequest so that i could call another function in Onreadystatechange

here is code which is working in all browsers but IE7 and IE8
C#
(function(open) {

    XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {

        this.addEventListener("readystatechange", function() {
          if(this.readyState == "4"){myfunction();}
        }, false);

        open.call(this, method, url, async, user, pass);
    };

})(XMLHttpRequest.prototype.open);



i changed it to this one to make it work in IE7 and IE8 but it doesn't work


C#
(function (open) {

    XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {

        this.attachEvent("onreadystatechange", function () {
            if (this.readyState == "4") { Myfunction(); }
        });

        open.call(this, method, url, async, user, pass);
    };

})(XMLHttpRequest.prototype.open);



but it's interesting that XmlHttpRequest doesn't support neither attachEvent nor addEventListener.

Thanks
Posted
Comments
Krunal Rohit 19-Feb-14 11:31am    
What about ActiveXObject ?
mehdijafary 19-Feb-14 11:34am    
in IE7 and IE8 it does support XMLHttpRequest

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900