Example.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <?php
  9. if(@$_GET["action"]=="getTime"){
  10. $time1 = Time()+13000;
  11. $date1 = date("H:i:s T",$time1);
  12. echo '<font size="5" color="#000000">'.$date1.'</font><br>';
  13. die();
  14. }
  15. ?>
  16. <div id="qwe">test</div>
  17. <script type="text/javascript">
  18. window.onload = startInterval;
  19. function startInterval() {
  20. setInterval("startTime();",1000);
  21. }
  22. function startTime() {
  23. AX = new ajaxObject("?action=getTime", showTime)
  24. AX.update(); // start Ajax Request
  25. }
  26. // CallBack
  27. function showTime( data ){
  28. document.getElementById('qwe').innerHTML = data;
  29. }
  30. </script>
  31. <script type="text/javascript">
  32. // Ajax Object - Constructor
  33. function ajaxObject(url, callbackFunction) {
  34. var that=this;
  35. this.updating = false;
  36. this.abort = function() {
  37. if (that.updating) {
  38. that.updating=false;
  39. that.AJAX.abort();
  40. that.AJAX=null;
  41. }
  42. };
  43. this.update =
  44. function(passData,postMethod) {
  45. if (that.updating) { return false; }
  46. that.AJAX = null;
  47. if (window.XMLHttpRequest) {
  48. that.AJAX=new XMLHttpRequest();
  49. }else{
  50. that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  51. }
  52. if (that.AJAX==null) {
  53. return false;
  54. }else{
  55. that.AJAX.onreadystatechange = function() {
  56. if (that.AJAX.readyState==4) {
  57. that.updating=false;
  58. that.callback( that.AJAX.responseText, that.AJAX.status, that.AJAX.responseXML, that.AJAX.getAllResponseHeaders() );
  59. that.AJAX=null;
  60. }
  61. };
  62. that.updating = new Date();
  63. if (/post/i.test(postMethod)) {
  64. var uri=urlCall+(/\?/i.test(urlCall)?'&':'?')+'timestamp='+that.updating.getTime();
  65. that.AJAX.open("POST", uri, true);
  66. that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  67. that.AJAX.setRequestHeader("Content-Length", passData.length);
  68. that.AJAX.send(passData);
  69. }else{
  70. var uri=urlCall+(/\?/i.test(urlCall)?'&':'?')+passData+'&timestamp='+(that.updating.getTime());
  71. that.AJAX.open("GET", uri, true);
  72. that.AJAX.send(null);
  73. }
  74. return true;
  75. }
  76. };
  77. var urlCall = url;
  78. this.callback = callbackFunction || function (){};
  79. }
  80. </script>
  81. </body>
  82. </html>