AJAX異步提交的簡單例子

  1. <html>
  2. <head>
  3.  <script language='javascript'>
  4.   <!--
  5.    var xmlHttp;
  6.    try
  7.     {
  8.       xmlHttp= new ActiveXObject("Msxml12.XMLHTTP");
  9.     }
  10.     catch(e)
  11.     {
  12.       try
  13.        {
  14.          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  15.          
  16.        }
  17.         catch(e){
  18.          try{
  19.           xmlHttp=new XMLHttpRequest();
  20.         }catch(e){}
  21.       }
  22.      }
  23.   //
  24.    xmlHttp.onreadystatechange=function(){
  25.     if(xmlHttp.readState==4){
  26.       if(xmlHttp.state==200){
  27.           alert(xmlHttp.responseText);
  28.              }
  29.       else{
  30.         alert(xmlHttp.status);
  31.         }
  32.      }
  33. }
  34.     xmlHttp.open("get","test.htm");
  35.     xmlHttp.send(null);
  36.   -->
  37. </script>
  38. </head>
  39. <body>
  40. </body>
  41. </html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章