jquery ajax 显示服务器时钟

Posted on 2015-06-22 01:14  小蕊同学  阅读(316)  评论(0编辑  收藏  举报
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>无标题文档</title>
  6. </head>
  7. <body>
  8. <h1 id="tt"></h1>
  9. </body>
  10. </html>
  11. <script>
  12. function $(id){
  13. return document.getElementById(id);
  14. }
  15. var x=new XMLHttpRequest();
  16. x.onreadystatechange=function(){
  17. if(x.status==200&&x.readyState==4){
  18. //alert(x.responseText);可以直接打印出来
  19. $('tt').innerHTML = x.responseText;
  20. }
  21. }
  22. function myt(){
  23. x.open('GET','a.php?'+new Date());
  24. x.send(null);
  25. }
  26. setInterval(myt,1000);
  27. </script>
a.php页面代码
  1. <?php
  2. echo date('Y-m-d H:i:s');






Copyright © 2024 小蕊同学
Powered by .NET 8.0 on Kubernetes