Ajax.html 909 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script type="text/javascript">
  5. function ajaxFunction()
  6. {
  7. var xmlhttp;
  8. //判断浏览器
  9. if (window.XMLHttpRequest)
  10. {
  11. xmlhttp=new XMLHttpRequest();
  12. }
  13. else
  14. {
  15. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  16. }
  17. //每当readyState 改变时,就会触发 onreadystatechange 事件
  18. xmlhttp.onreadystatechange=function()
  19. {
  20. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  21. {
  22. document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  23. }
  24. }
  25. //XMLHttpRequest.open('post', url, true);
  26. xmlhttp.open("post","visit.jsp",true);
  27. //在利用xmlhttp的send()提交表格,并且需要在服务器端通过request.getParameter("paraName")来就收的话,先要加入header参数
  28. xmlhttp.send();
  29. }
  30. </script>
  31. </head>
  32. <body>
  33. <button type="button" onclick="ajaxFunction()" >点击刷新访客量</button>
  34. <div id="myDiv"></div>
  35. </body>
  36. </html>