Getting data from MySql table with no refresh

Getting data from MySql table with no refresh

Hello,

I have a code that counts down and when the countdown reaches 0 I want it to grab data from a MySql table and present it on the page without reloading.

I know my countdown works, but it is when I add the code to get the data from the PHP page it stops working. I know my PHP page works and grabs the correct data and presents it.

Here is the code I am currently using, row 40, 41 and 42 are the lines that I added to try and get the PHP data. Any ideas? Thanks.
  1. <div id="countmesg">
  2. </div>

  3. <div id="checking">
  4. </div>
  5. <div id="name-data">
  6. </div>


  7. <script src="jquery.js" type="text/javascript"></script>

  8. <script type="text/javascript">

  9. $(document).ready(function() {
  10. var delay = 10 ;
  11. function countdown() {
  12. setTimeout(countdown, 1000) ;
  13. $('#countmesg').html("Auction ends in "  + delay  + " seconds.");
  14. delay --;
  15. if (delay < 0 ) {
  16. $('#countmesg').html("Auction ended.");
  17. delay = 0 ;
  18. }
  19. }
  20. countdown() ;
  21. });
  22. </script>

  23. <script type="text/javascript">

  24. $(document).ready(function() {
  25. var delay = 2 ;
  26. function countdown() {
  27. setTimeout(countdown, 100) ;
  28. $('#checking').html("Checking in "  + delay  + " seconds.");
  29. delay --;
  30. if (delay < 0 ) {
  31. $('#checking').html("Checking again....");
  32. var name = 'tom';
  33. $.post('cdown.php', {name: name}, function(data) {
  34. $('div#name-data').text(data);
  35. };
  36. delay = 2 ;
  37. }
  38. }
  39. countdown() ;
  40. });
  41. </script>