ajax 之XMLHttpRequest两种创建方法

/**//* 创建XMLHttpRequest的第一种方法
     try{
             searchReq = new ActiveXObject('Msxml2.XMLHTTP');
        }
         catch(e){
             try{
                searchReq = new ActiveXObject('Microsoft.XMLHTTP');
             }
            catch(e){
                try{
                     searchReq = new XMLHttpRequest();
                 }
                 catch(e)
                 {}
            }
         }
         */
     //创建XMLHttpRequest的第二种方法
     function createReq(){
         var httpReq;
       
         if(window.XMLHttpRequest){
             httpReq = new XMLHttpRequest();
             if(httpReq.overrideMimeType){
                 httpReq.overrideMimeType('text/xml');
             }
        }
         else if(window.ActiveXObject){
             try{
                  httpReq = new ActiveXObject('Msxml2.XMLHTTP');
             }
            catch(e){
                 try{
                         httpReq = new ActiveXObject('Microsoft.XMLHTTP');
                 }
                 catch(e){
                 }
             } 
         }
         return httpReq;
      }

你可能感兴趣的:(ajax 之XMLHttpRequest两种创建方法)