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>