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>
  • 相关阅读:
    关于路径的小知识点
    转发与重定向
    一种反复的读写文件的方法
    文字排版reportlab
    Qgis中插件的安装位置
    spyder打开文件假死解决
    地图跳跃-超级码力
    尾部的零
    一探torch.nn究竟“What is torch.nn really?”
    KAZE特征和各向异性扩散滤波
  • 原文地址:https://www.cnblogs.com/gaoxuerong123/p/8558124.html
Copyright © 2011-2022 走看看