javascript - 倒计时完成后如何移动窗口?
问题描述
您好,我用 php 和 javascript 创建了一个倒计时。我有三个文件 test.php、mentenanta.php 和 response.php,它工作正常,但是当倒计时结束时,我想自动回到 index.php。这是我的文件:
测试.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() 来停止它。
解决方案
推荐阅读
- c# - 为什么 OracleDataAdapter 在 C# 中断开连接?
- python - 将每个元素的大小定义为python中多维数组形状中的第三维/参数
- javascript - 提交按钮未在 ASP.NET MVC Web 应用程序中触发
- c++ - 我可以在 MacOS X 10.8 VM 上编译 c++ 以在当前的 Mac 上工作还是需要使用 MacOS 10.12 VM?
- css - 位置绝对时如何获得响应行为
- pandas - 熊猫转换为日期时间,dateutilparser 错误
- python - 从python中的库导入时出错
- python - 使用 tf.keras.optimizers.SGD 时出现 TensorFlow 错误
- ios - cocoapod 如何处理传递依赖
- java - System.out.println 它没有显示在终端中