创建通用XMLHttpRequest对象

 

   function createXmlHttpRequestObject()
   {
        if (window.XMLHttpRequest)   
        {    xmlhttp_request = new XMLHttpRequest();    }
            else
            {    var MSXML=['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
                for(var n = 0; n < MSXML.length; n ++)
                {   
                    try  
                     {   
                     xmlhttp_request = new ActiveXObject(MSXML[n]); 
                       break; 
                     }
                    catch(e){}
                }
            }

 

}

function createXmlHttp()
{
    var oXmlHttp = null;
    if (window.ActiveXObject) // IE
   {
        try{oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
         catch (e){try{oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}catch (e){}}
    }
    else
    {
   if (window.XMLHttpRequest) // Mozilla, Safari,
   {
        oXmlHttp = new XMLHttpRequest();
        if (oXmlHttp.overrideMimeType)
       {
           oXmlHttp.overrideMimeType('text/xml');
       }
    }
    }
    if (!oXmlHttp)
   {
        alert('错误:不能创建 XMLHTTP 实例');
    }
    return oXmlHttp;
}

 

 

作者:边写边唱

文章出处:http://www.cnblogs.com/zoupeiyang

专注于用自助终端技术实现互联网+,有兴趣朋友欢迎关注   捷思科技

posted on 2009-03-23 08:37  边写边唱  阅读(411)  评论(0编辑  收藏  举报

导航