0

I am trying to build deals aggregator which will load deals by AJAX, but the problem for me is to do multiple countdown timers (one for each deal) with dates from MySQL. I was trying to do something like code below but this doesn't work. Can someone give me the best solution to do it, please?

jQuery code:

$(document).ready(function(){

$.ajax({
url:"getdata.php",
type:"GET",
dataType:'json',
success:function(rows){

for (var i in rows){
var row=rows[i];
var id=row[0];
var end_date=row[1];
$("#countdown_"+id).countdown({
            date: end_date,
            format: "on"
        },

        function() {
        // callback function
        });
}
}
});
});

PHP code:

$data=array();
while($row=mysql_fetch_row($result))
{
    $data[]=$row;
}
die (json_encode($data));
4
  • What does doesn't work mean? Not very informative, especially considering you have code have running on two environments and AJAX talking between the two Commented Feb 10, 2013 at 2:14
  • when I am using this code, the only last timer is counting down, the others are getting dates but are not counting down, just showing the same value all the time Commented Feb 10, 2013 at 2:29
  • there are numerous timer plugins.. which are you using? Commented Feb 10, 2013 at 2:32
  • I was trying to use this one webdesign.tutsplus.com/tutorials/complete-websites/… Commented Feb 10, 2013 at 2:42

1 Answer 1

1

Plugin was written with some global variables that wouldn't allow for multiple instances.

I made a few adjustments that made it work

See Demo: http://jsfiddle.net/afRVm/1

.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.