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.
- <div id="countmesg">
- </div>
- <div id="checking">
- </div>
- <div id="name-data">
- </div>
- <script src="jquery.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- var delay = 10 ;
- function countdown() {
- setTimeout(countdown, 1000) ;
- $('#countmesg').html("Auction ends in " + delay + " seconds.");
- delay --;
- if (delay < 0 ) {
- $('#countmesg').html("Auction ended.");
- delay = 0 ;
- }
- }
- countdown() ;
- });
- </script>
- <script type="text/javascript">
- $(document).ready(function() {
- var delay = 2 ;
- function countdown() {
- setTimeout(countdown, 100) ;
- $('#checking').html("Checking in " + delay + " seconds.");
- delay --;
- if (delay < 0 ) {
- $('#checking').html("Checking again....");
- var name = 'tom';
- $.post('cdown.php', {name: name}, function(data) {
- $('div#name-data').text(data);
- };
- delay = 2 ;
- }
- }
- countdown() ;
- });
- </script>