1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Getting data from MySql table with no refresh

Discussion in 'jQuery' started by leequery, Feb 4, 2014.

  1. #1
    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>
    
    Code (markup):
     
    leequery, Feb 4, 2014 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    Have you checked what the server response is? Any errors? Got a live link?

    Just quickly reading your code and I can see you are doing a lot of work for nothing. Why not just use setInterval to call the countdown function rather than using all of this delay stufff?
     
    HuggyStudios, Feb 5, 2014 IP