0

Jquery Countdown プラグインを使用してカウントダウンを作成したいと考えています。AJAX を介して PHP に接続する必要があります。基本的に、ポータルにはこのカウントダウンが必要です (その URL よりも 12 時間以上前の URL がある場合、その URL は Mysql から自動的に削除されます)。

このためのコードを設計しましたが、AJAX 呼び出しを使用すると正しく機能しません。ajax呼び出しを期待して正常に動作しています。

コードを見てください。

HTML / Javascript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>jQuery Countdown</title>
<link href="jquery.countdown.css" type="text/css" rel="stylesheet">
<style type="text/css">
#defaultCountdown { width: 240px; height: 45px; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://keith-wood.name/js/jquery.countdown.js">          </script>
<script type="text/javascript">
function serverTime(){ 
var time = null; 
$.ajax({url: 'http://localhost/portal/audit/test3.php', 
    async: false, dataType: 'text', 
    success: function(text) { 
        time = new Date(text); 
    }, error: function(http, message, exc) { 
        time = new Date(); 
}}); 
return time; 
}
$('#defaultCountdown').countdown({ 
until:liftoffTime, serverSync: serverTime}); 
   </script>
   </head>
    <body>
    <div id="defaultCountdown"></div>
    </body>
    </html>

PHPコード

<?php 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Fri, 1 Jan 2010 00:00:00 GMT"); // Date in the past 
header("Content-Type: text/plain; charset=utf-8"); // MIME type 
$now = new DateTime(); 
echo $now->format("M j, Y H:i:s O")."\n"; 
?>

このカウントダウン プラグインを提案してください。このプラグインは次の URL から使用しました:- http://keith-wood.name/countdownRef.html#serverSync

更新しました

<script type="text/javascript">
function liftOff() { 
    var time = null; 
    $.ajax({url: 'http://localhost/portal/audit/test3.php', 
        async: false, dataType: 'text', 
        success: function(text) { 
            time = new Date(text); 
        }, error: function(http, message, exc) { 
            time = new Date(); 
    }}); 
    return time; 
}
$('#defaultCountdown').countdown({ 
    until:liftoffTime, onExpiry: liftOff}); 



</script>
4

1 に答える 1

0

答えはページにあります。コールバック「onExpiry」を使用する必要があります。

$(selector).countdown({ 
    until: liftoffTime, onExpiry: liftOff}); 

function liftOff() { 
    // run ajax here
}
于 2012-04-24T07:05:42.717 に答える