6

I hope both the object invocations are referring to the ActiveXObject. But why are we passing two different parameters to work in IE. 1. Msxml2.XMLHTTP and 2. Microsoft.XMLHTTP

Are they both same ? Or Are they browser dependent(IE7 and IE8) ?

I used both. I did not get any exception. Both are looking same for me. I am using IE 8.

2 Answers 2

9

Both are actually outdated. There are various versions of Microsoft's venerable MSXML ActiveX object (I believe the last one was version 5.0 and came with some version of Office.) The versions have minor differences in behavior, and bug fixes that usually don't come into play in AJAX scenarios.

Starting with IE7, Microsoft supported the standardized "XmlHttpRequest" object that other modern browsers had adopted. See http://msdn.microsoft.com/en-us/library/ms537505(VS.85).aspx. You should definitely be using that as IE7 is now the de-facto lowest common denominator. IE6 has been declared dead by most major organizations, so there's no reason to support the old Microsoft-specific ActiveX ProgIDs.

And of course, there is very little reason these days to roll your own AJAX calls, as libraries like jQuery and ASP.NET Ajax do it for you, abstracting away these obscure browser quirks. I would strongly suggest learning one of those libraries.

Jordan Rieger

2

jquery (at least 1.4.2) has problem on $.ajax() calling. It makes great memory leakage (like fountain) tragedy code:

if ( window.ActiveXObject ) {
    jQuery.ajaxSettings.xhr = function() {
        if ( window.location.protocol !== "file:" ) {
            try {
                return new window.XMLHttpRequest();
            } catch(xhrError) {}
        }

        try {
            return new window.ActiveXObject("Microsoft.XMLHTTP");
        } catch(activeError) {}
    };
}

resolution:

if ( window.ActiveXObject ) {
    jQuery.ajaxSettings.xhr = function() {
        if ( window.location.protocol !== "file:" ) {
            if ( window.ActiveXObject ) {
                try {
                    return new window.ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
            try {
                return new window.XMLHttpRequest();
            } catch(xhrError) {}
        }

        try {
            return new window.ActiveXObject("Microsoft.XMLHTTP");
        } catch(activeError) {}
    };
}
2
  • Your resolution does not need the inner ActiveXObject check. It will always be true.
    – user169771
    Mar 11, 2015 at 18:50
  • this is how to perform a check for ActiveXObject if('ActiveXObject' in window){return new ActiveXObject("Microsoft.XMLHTTP")}
    – Sharif
    Jul 27, 2017 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.