开发者

JavaScript: Which should I use, Microsoft.XMLHTTP or Msxml2.XMLHTTP?

开发者 https://www.devze.com 2022-12-14 17:54 出处:网络
There are two progid\'s.I\'ve seen开发者_如何学C both used. Anyone have any insight as to when I should use one, versus the other? You should definitely not use Microsoft.XmlHttp.

There are two progid's. I've seen开发者_如何学C both used.

Anyone have any insight as to when I should use one, versus the other?


You should definitely not use Microsoft.XmlHttp.

From the Microsoft XML Team blog: Using the right version of MSXML in Internet Explorer: (archive)

MSXML2 vs. Microsoft namespace – I’ve also seen a lot of code that instantiates the "Microsoft.XMLHTTP" ActiveX object rather than the MSXML2.XMLHTTP.3.0 or MSXML2.XMLHTTP.6.0 if you’re using 6.0. The “Microsoft” namespace is actually older and is only implemented in MSXML3 for legacy support. It’s unfortunate we used the “better” name on the older version, but stick to the “msxml2” namespace when instantiating objects.


Hai Cheeso,

Have a look at these
http://bytes.com/topic/javascript/answers/559991-msxml-xmlhttp-vs-microsoft-xmlhttp

http://forums.asp.net/p/1000060/1622845.aspx


Maybe not exactly the answer you want, but that, if you are developping an Ajax application, I'd say you shouldn't use either of those : instead, you should use a Javascript Framework that will deal with browser compatibility, and not re-fight that battle.

For instance (there are many more) :

  • prototype
  • jQuery
  • YUI

And, as a sidenote, they'll get you plenty of other useful stuff ;-)


This code takes care of both IE and firefox.

try {
  XMLHttpRequestObject = new ActiveXObject("MSXML2.XMLHTTP");
} catch (exception1) {
  try {
    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (exception2) {
    XMLHttpRequestObject = false;
  }
}

if (!XMLHttpRequestObject && window.XMLHttpRequest) {
  XMLHttpRequestObject = new XMLHttpRequest();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消