简体   繁体   English

jQuery的倒计时插件与多个ajax调用?

[英]jquery countdown plugin with multiple ajax call?

im trying to send multiple calls to php file through jquery ajax and print a count down timer using this Jquery plugin CountDown 我试图通过jquery ajax将多个调用发送到php文件,并使用此Jquery插件CountDown打印一个倒数计时器

JS 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

<?php
$now = time() + 9999; 
echo date("M j, Y H:i:s",$now)."\n"; 
$now1 = time() + 999; 
echo date("M j, Y H:i:s",$now1)."\n"; 
?>

i need to show each time printed into separated div but this is what i got 我需要显示每次打印到单独的div中,但这就是我得到的

NaN:NaN:NaN

NaN:NaN:NaN

Your ajax potion need to be change 你的ajax药水需要改变

 $.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代码

 <?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)));
 ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM