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

大兔子大兔子 提交于 2019-12-21 06:19:35

问题


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.


回答1:


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) {}
    };
}


来源:https://stackoverflow.com/questions/3993598/ajax-call-what-is-the-difference-between-new-activexobjectmsxml2-xmlhttp-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!