js读取文本文件-xmlHTTP

来源:互联网 发布:js鼠标移入图片放大 编辑:程序博客网 时间:2024/06/02 18:50
  1. <html>  
  2.     <head>  
  3.     </head>  
  4.     <body>  
  5.     <span id="aaa"></span>  
  6.        
  7.     <script>  
  8.     var xmlHttp;   
  9.     var rs;   
  10.     var isie = false;   
  11.     function startRequest(url,divs){   
  12.         if(window.ActiveXObject){   
  13.             xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
  14.             isie = true;   
  15.         }else if(window.XMLHttpRequest){   
  16.             xmlHttp = new XMLHttpRequest();   
  17.         }   
  18.         try{   
  19.             if(isie == false ){   
  20.                 xmlHttp.open("GET", url, false);   
  21.                 xmlHttp.overrideMimeType("text/html;charset=gb2312");   
  22.                 xmlHttp.send(null);   
  23.                 document.getElementById(divs).innerHTML=xmlHttp.responseText;   
  24.             }else{   
  25.                 xmlHttp.open("GET", url, false);   
  26.                 xmlHttp.send(null);   
  27.                 if(xmlHttp.readyState == 4){           
  28.                     if (xmlHttp.status == 200 || xmlHttp.status == 0){   
  29.                      document.getElementById(divs).innerHTML=Recenspace(xmlHttp.responseBody);   
  30.                     }   
  31.                 }   
  32.             }    
  33.         }catch(exception){   
  34.             document.write('exception:'+exception.message);   
  35.         }   
  36.     }   
  37.     function Recenspace(Html){   
  38.         rs=new ActiveXObject("ADODB.RecordSet");   
  39.         rs.fields.append("a",201,1);   
  40.         rs.open();         
  41.         rs.addNew();   
  42.         rs(0).appendChunk(Html);   
  43.         rs.update();   
  44.         return rs(0).value;   
  45.         rs.close();   
  46.     }   
  47.         startRequest('src.txt','aaa');   
  48.     </script>  
  49.     </body>  
  50. </html>