Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax call: What is the difference between new ActiveXObject("Msxml2.XMLHTTP") and new ActiveXObject("Microsoft.XMLHTTP")?

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.

like image 881
Puru Avatar asked Oct 22 '10 03:10

Puru


People also ask

What is Microsoft Xmlhttp?

XMLHTTP is a set of APIs that can be used by JavaScript, JScript, VBScript and other browser scripting languages to transfer XML or other data to and from a HTTP web server.

What is the difference between XMLHttpRequest and AJAX?

XHR is the XMLHttpRequest Object which interacts with the server. Ajax technique in the nutshell leverages the XHR request to send and receive data from the webserver. This object is provided by the browser's javascript environment. It transfers the data between the web browser and server.

What is window Activexobject in JavaScript?

An ActiveX object is an instance of a class that exposes properties, methods, and events to ActiveX clients. ActiveX objects support the COM. An ActiveX component is an application or library that is capable of creating one or more ActiveX objects.

What is the purpose of XMLHttpRequest in AJAX?

XMLHttpRequest (XHR) objects are used to interact with servers. You can retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without disrupting what the user is doing. XMLHttpRequest is used heavily in AJAX programming.


2 Answers

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

like image 162
Jordan Rieger Avatar answered Nov 15 '22 08:11

Jordan Rieger


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) {}
    };
}
like image 36
Rocky Avatar answered Nov 15 '22 07:11

Rocky