创建通用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;
}

 

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

导航