如何在时间到期时自动提交
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#online").load("./tmr.php");
var refreshId = setInterval(function() {
//alert("aa");
$("#online").load('./tmr.php');
$.ajax({
type: "POST",
url: "./update.php",
data: "stdID="+aa
})
}, 1000);
$.ajaxSetup({ cache: false });
});
</script>
the php code is
<?php
session_start();
$aa = $_SESSION['member'];
include 'connect.php';
$result = mysql_query("SELECT tmr_left FROM account WHERE member='$aa'");
$count = mysql_num_rows($result);
$tmr = mysql_result($result,0,"tmr_left");
$dateFormat = "d F Y -- g:i a";
$targetDate = time() + (30*60);//Change the 25 to however many minutes you want to countdown
$actualDate = time();
$secondsDiff = $tmr; = 1800 = 30 mins
$remainingDay = floor($secondsDiff/60/60/24);
$remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$actualDateDisplay = date($dateFormat,$actualDate);
$targetDateDisplay = date($dateFormat,$targetDate);
echo $remainingMinutes.":".$remainingSeconds;
?>
并按间隔保存
<?php
include 'connect.php';
$result = mysql_query("SELECT tmr_left FROM account WHERE member='".$_POST['stdID']."'");
$tmr = mysql_result($result,0,"tmr_left");
$tmr -=1;
$command = mysql_query("UPDATE account SET tmr_left='".$tmr."' WHERE member='".$_POST['stdID']."'") or die(mysql_error());
?>
它不是纯粹的JavaScript,但是当时间用完时,是否有任何可行的方法来放置.submit()?每秒在我的数据库中保存的时间