DISPLAY DATE/TIME ON WEBSITE WITHOUT REFRESHING PAGE--HELP!


SUBMITTED BY: Guest

DATE: Nov. 7, 2013, 3:13 p.m.

FORMAT: Text only

SIZE: 3.5 kB

HITS: 1186

  1. I want to display the time and date on my website in real-time, and so far I got the time to display, but it's static server time. How do I get it so that it actually scrolls by without the visitor having to refresh the page?
  2. This is what I have so far:
  3. //////////////
  4. //index.php //
  5. //////////////
  6. <?php
  7. ///////////////////////////////
  8. require_once('datetime.php');// datetime.php IS SPELLED OUT FURTHER DOWN THE PAGE--I'M NOT EVEN SURE IF 'require_once' IS
  9. /////////////////////////////// THE CORRECT THING TO PUT HERE
  10. echo "<!DOCTYPE html>
  11. <html>
  12. <head>
  13. /////////////////////////////////////////////////////////////////////////////////////
  14. <script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>//
  15. //
  16. <script src='scripts.js'></script> //SHOULD THESE SCRIPT REFERENCES
  17. //BE HERE? ARE THEY THE RIGHT ONES?
  18. <script type='text/javascript' src='jquery-1.4.1.min.js'></script> //DO I NEED MORE TO MAKE IT WORK?
  19. /////////////////////////////////////////////////////////////////////////////////////
  20. </head>
  21. <body>
  22. /////////////////////////////////////////
  23. <script type='text/javascript'> //
  24. $(document).ready(function() { //
  25. function update() { //
  26. $.ajax({ //
  27. type: 'POST', //
  28. url: 'datetime.php', //
  29. timeout: 1000, //
  30. success: function(data) { // NOT SURE WHERE THIS SECTION SHOULD BE PLACED
  31. $('#timer').html(data); // ANYWHERE IN THE BODY? AFTER THE OPENING BODY TAG?
  32. window.setTimeout(update, 1000); // BEFORE THE CLOSING BODY TAG? IN THE HEAD?
  33. }, //
  34. }); //
  35. } //
  36. }); //
  37. //
  38. </script>"; //
  39. /////////////////////////////////////////
  40. echo "<div id='timer'>";//
  41. echo $msg; // HERE'S WHERE THE TIME IS DISPLAYED, BUT IT'S JUST STATIC SERVER TIME
  42. echo "</div>"; // AT THE STROKE OF MIDNIGHT I WANT THE DAY TO SCROLL OVER WITHOUT VISITOR HAVING TO REFRESH
  43. ////////////////////////// I WANT IT TO APPEAR JUST LIKE YOU'RE LOOKING AT A DIGITAL WATCH
  44. echo "</body>";
  45. echo "</html>;
  46. ?>
  47. /////////////////
  48. //datetime.php //
  49. /////////////////
  50. <?php
  51. $mlscmsg = date('T');
  52. $secmsg = date('s');
  53. $minmsg = date('i');
  54. $datemsg = date('j');
  55. $yearmsg = date('Y');
  56. $monthmsg = date('F');
  57. $daymsg = date('l');
  58. $timemsg = date('g');
  59. $ampmmsg = date('A');
  60. $msg = "<strong>You were here on " . $daymsg . ", " . $monthmsg . " " . $datemsg . ", " . $yearmsg . " at " . $timemsg . ":" . $minmsg . ":" . $secmsg . " " . $ampmmsg . " " . $mlscmsg . "</strong>";
  61. ?>
  62. THE CLOCK OUTPUT CAN BE SEEN ON http://funkyfaucet.tk
  63. if anyone knows how to make this appear in the browser as an actual clock, with seconds, minutes, days, etc. scrolling in real time, please contact "funkmaster" on peerbet.org

comments powered by Disqus