你好,我用php和javascript创建了一个倒计时。我有三个文件test.php,mentenanta.php和response.php,它可以正常工作,但是当倒计时结束时,我想自动返回index.php。这是我的文件:
test.php
<?php
$_SESSION["duration"] = $mentenanta[0]['finish_time'];
$_SESSION["start_time"] = date("Y-m-d H:i:s");
$end_time = date('Y-m-d H:i:s', strtotime('+'.$_SESSION["duration"].'minutes', strtotime($_SESSION["start_time"])));
$_SESSION["end_time"] = $end_time;
?>
<script type="text/javascript">
window.location="mentenanta.php";
</script>
这是 mentenanta.php
<?php session_start(); ?>
<div id="response"></div>
<script type="text/javascript">
setInterval(function()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","response.php",false);
xmlhttp.send(null);
document.getElementById("response").innerHTML=xmlhttp.responseText;
},1000)
</script>
这是 response.php
<?php
session_start();
$from_time1 = date('Y-m-d H:i:s');
$to_time1 = $_SESSION["end_time"];
$timefirst=strtotime($from_time1);
$timesecond=strtotime($to_time1);
$differenceinseconds=$timesecond-$timefirst;
if($timesecond > $timefirst){
echo gmdate("H:i:s", $differenceinseconds);
}
?>
它工作正常,但是我不知道如何设置在计时器结束到index.php或其他文件时自动移动标头,当然也不设置XmlHttpsRequest.abort()来停止它。