zoukankan      html  css  js  c++  java
  • ajax

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title></title>
     6     </head>
     7     <body>
     8          <a href="helloajax.txt">11111111111</a>
     9     </body>
    10     <script>
    11         window.onload = function(){
    12             document.getElementsByTagName('a')[0].onclick = function(){
    13                 var XHR=new XMLHttpRequest();
    14                 var url = this.href+'?time='+new Date();
    15                 var methods = 'get';
    16                 XHR.open(methods,url);
    17                 XHR.send(null);
    18                  XHR.onreadystatechange = function(){
    19                      alert(XHR.readyState)
    20                      if(XHR.readyState==4){
    21                          if(XHR.status==200||XHR.status==304){
    22                              alert(XHR.responseText);
    23                          }
    24                      }
    25                  }
    26             }
    27              
    28             return false; 
    29         }    
    30     </script>
    31 </html>
     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title></title>
     6     </head>
     7     <body>
     8         <a href="helloajax.txt">helloajax</a>
     9         <div id="content"></div>
    10     </body>
    11     <script type="text/javascript" src="js/jquery-2.0.3.js" ></script>
    12     <script>
    13         $(fiunction(){
    14             $('a').click(function(){
    15                 var url = this.href;
    16                 var args = {"time":new Date()};
    17                 $('#content').load(url,args);
    18                 return false;
    19             })
    20         })
    21     </script>
    22 </html>
     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title></title>
     6     </head>
     7     <body>
     8          <a href="helloajax.txt">11111111111</a>
     9     </body>
    10     <script>
    11         window.onload = function(){
    12             document.getElementsByTagName('a')[0].onclick = function(){
    13                 var XHR=new XMLHttpRequest();
    14                 var url = this.href;
    15                 var methods = 'post';
    16                 XHR.open(methods,url);
    17                 XHR.setRequestHeader('ContentType',"application/x-www-form-urlencoded");
    18                 XHR.send("address=' 武汉'");
    19                  XHR.onreadystatechange = function(){
    20                      if(XHR.readyState==4){
    21                          if(XHR.status==200||XHR.status==304){
    22                              alert(XHR.responseText);
    23                          }
    24                      }
    25                  }
    26             }
    27              
    28             return false; 
    29         }    
    30     </script>
    31 </html>
  • 相关阅读:
    C# UDP实现通信的方法
    Leetcode 559. N叉树的最大深度
    101. 对称二叉树
    108. 将有序数组转换为二叉搜索树
    剑指 Offer 55
    Linux
    Linux
    Linux
    Linux
    Linux
  • 原文地址:https://www.cnblogs.com/gaoxuerong123/p/8558124.html
Copyright © 2011-2022 走看看