は、次の操作を行いたい:外部PHP残量時間カウンタを使用したjquery。複数の実行
1)各3分のjqueryのは、実行を開始する外部のphpになり、セッション値
2をチェックします)外部のPHPから(戻り)と残り時間を表示しますカウンタ
最初の3分後、すべてが正常に動作します。しかし、2番目の3分後には、function updateClock ()
が2回、3番目の3分後に3回実行されたようになります。
$('#remaining_time').html()
を実行するたびにリセットするにはどうすればよいですか?外部PHPの挿入では、?> <script type="text/javascript">$('#remaining_time').html('');</script> <?php
のようなjavascriptを試してみましたが、それは役に立ちません。それぞれの実行で残りの時間カウンタをリセットしたい。ここで
あなたはAJAX呼び出しのコールバックでもsetInterval
を呼び出すと、次の2つを持っています(コードの一部)
Htmlの
<div class="div_show_hide" id="logout_warning_popup">
<div class="" style="position:absolute; width:100%; height:100%; left:0; bottom:0; background: rgba(199,199,199,0.9); display: table; ">
<div style="display: table-cell; vertical-align: middle; text-align:center;">
<span style="align:center; width:200px; height:200px; border:solid 0px red; background:#fff; padding:20px;">
Session will expire after <span id="remaining_time"></span> seconds.
</span>
<br/>
<span style="cursor:pointer; border:solid 1px green; margin:0 10px 0 0;" id="continue_session">Continue the session</span>
</div>
</div>
</div>
のjQuery
function logout_with_warning() {
$.post("_logout_warning.php", function(data_logout_warning) {
$('#logout_warning_popup').show();
var time_when_must_logout = new Date().setTime(new Date().getTime() + 1000 * 60 * 2);//2 minutes
$('#remaining_time').html('' + Math.round(((parseInt(time_when_must_logout,0) - parseInt((new Date().setTime(new Date().getTime())),0)))/1000));
function updateClock (){
$('#remaining_time').html('' + Math.round(((parseInt(time_when_must_logout,0) - parseInt((new Date().setTime(new Date().getTime())),0)))/1000));
}
setInterval(updateClock, (1000*1));// one second
});
}
setInterval(logout_with_warning, (60000*3));
setTimeout()関数を使用するか、clear timerを設定する前にclearInterval()を実行してください。 – diavolic