我正在使用一些 JavaScript 来检查倒计时小时分钟目标,然后启动 php 页面:
window.setInterval(function() { // Set interval for checking
var date = new Date();
if (date.getHours() === 13 && date.getMinutes() === 31) { // Check the time
location.href = "real_live.php?lotnum=1";
}
}, 1000); // Repeat every 1000 milliseconds (1 second)
它目前正在使用客户端时钟并且功能完美。但是,我需要使用服务器端时钟并尝试,因为我可能还没有找到执行此操作的工作方法。你能给建议吗?
最佳答案
为此,您应该有两个单独的后端脚本。一个用于客户端将触发的计时器,如果它达到您想要的时间,您就会触发时间敏感的脚本。
所以,
xhr.open("GET", "/time.php", false);
xhr.onload = function (e){
//do your magic with the results to real_live.php
}
关于javascript - 在 JavaScript 中使用服务器端时钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30437968/