zoukankan      html  css  js  c++  java
  • 创建xmlHTTPRequest对象

    function getRequest() {
            http_request = false;
            if (window.XMLHttpRequest) {  
                //对于Mozilla﹑Netscape﹑Safari等浏览器,创建XMLHttpRequest  
                http_request = new XMLHttpRequest();
                if (http_request.overrideMimeType) {
                     //如果服务器响应的header不是text/xml,可以调用其它方法修改该header
                    http_request.overrideMimeType('text/xml');
                }
            } else if (window.ActiveXObject) {  
    // 对于Internet Explorer浏览器,创建XMLHttpRequest  
                try {
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {}
                }
            }
    return http_request;
    }

    2、第二种:

    function getHttpRequest()
    {
       var xmlreq = false;
       if (window.XMLHttpRequest) {
    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();
       } else if (window.ActiveXObject) {
    // Create XMLHttpRequest via MS ActiveX
    try {
       // Try to create XMLHttpRequest in later versions
       // of Internet Explorer
       xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
       // Failed to create required ActiveXObject
       try {
           // Try version supported by older versions
           // of Internet Explorer
           xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (e2) {
           // Unable to create an XMLHttpRequest with ActiveX
       }
    }
       }
       return xmlreq;
    }


    3.第三种:
    function CreateXMLHttp()

           {

             if(typeof(XMLHttpRequest) != "undefined")

             {

                return new XMLHttpRequest();

             }

             else if(window.ActiveXObject)

             {


                 var
    aVersions=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];

                for(var i=0;i<aVersions.length;i   )

                {

                       try

                       {

                         var oXmlHttp = new ActiveXObject(aVersions);
                         return oXmlHttp;
                       }
                       catch(oError)
                       {
                         //alert('Create XMLHttp failed!');
                       }
                }
             }
             throw new Error('Create XMLHttp failed!');
           }

    转自:http://hi.baidu.com/qianjian21/blog/item/b09d58ece9f294d72f2e21cb.html

  • 相关阅读:
    mysql5.5的安装与配置(亲测版)
    CentOS 6.5升级Python和安装IPython(亲测可用)
    运维mysql基础
    linux命令巧用,随手记
    《大话设计模式》——建造者模式
    《大话设计模式》——外观模式
    《大话设计模式》——模版方法模式
    抽象类和接口的区别
    《大话设计模式》——原型模式
    《大话设计模式》——工厂方法模式
  • 原文地址:https://www.cnblogs.com/johnwonder/p/1701365.html
Copyright © 2011-2022 走看看