写的很牛×了~
function createXMLHttpRequest() {
    if (window.XMLHttpRequest) {
        //IE7+, FF, Opera, etc.
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        //IE6-
        var msxmls = new Array("Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP");
        for (var i in msxmls) {
            try { return new ActiveXObject(msxmls[i]); } catch (e) {}
        }
    }
    //not support
    return null;
}

解决方案 »

  1.   


    遍历这些对象选择一个创建成功的出来, 
    区别就是操作系统带的 MSXML 包的版本不一样,
    这些包是 ActiveX 控件, IE 和很多 Windows 应用都可能用到它.
    对于 Mozilla, Firefox, 直接用 
    var xmlHttp = new XMLHttpRequest();也就是说,只要能创建出一个 xmlHttp  即可。
      

  2.   

    垃圾代码
    if(window.ActiveXObject){ 
      try{
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
      }catch(e){
       try{
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0"); 
       }catch(e1){
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
       }
    }
    else if(window.XMLHttpRequest){ 
    xmlHttp = new XMLHttpRequest();