im trying to send multiple calls to php file through jquery ajax and print a count down timer using this Jquery plugin CountDown
JS
$(document).ready(function () {
$('.timer').each(function () {
var time = null;
$.ajax({
url: 'serverTime.php',
async: false,
dataType: 'text',
success: function (text) {
time = new Date(text);
},
error: function (http, message, exc) {
time = new Date();
}
});
$('.timer').countdown({
until: time,
compact: true,
format: 'HMS'
});
});
})
and this my PHP
<?php
$now = time() + 9999;
echo date("M j, Y H:i:s",$now)."
";
$now1 = time() + 999;
echo date("M j, Y H:i:s",$now1)."
";
?>
i need to show each time printed into separated div but this is what i got
NaN:NaN:NaN
NaN:NaN:NaN
Your ajax potion need to be change
$.ajax({
url: 'serverTime.php',
async: false,
dataType: 'json',
success: function(text) {
var time1 = new Date(text.time1);
var time2 = new Date(text,time1);
},
error: function(http, message, exc) {
time = new Date();
}
Also change the php code
<?php
$now = time() + 9999;
$now1 = time() + 999;
echo json_encode(array('time1' => date("M j, Y H:i:s",$now1),'time2' => date("M j, Y H:i:s",$now2)));
?>