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));
doesn't workmean? Not very informative, especially considering you have code have running on two environments and AJAX talking between the two