php上的重定向包括increase

Redirect on php include increase

本文关键字:包括 increase 重定向 php      更新时间:2023-09-26

我不确定这是否可能,但是。

如果我有一个php文件,我就像这样调用

<?php include 'number.php';?>

是一个每一两个小时增加的数字。

  • 如何主动查看号码是否发生了变化?
  • 当数字增加时,我如何触发一个声音警报,然后重定向?

我现在做的是在number.php

中使用"每5秒刷新一次"
<body onload="setInterval(function() {window.location.reload();}, 5000);">

然后我尝试使用jquery来控制台记录数字并检查增加的值,但我意识到这不会发生,所以我将为您省去混乱的代码。

这就是我想要触发的:

$("#alert").get(0).play();    
$(location).attr('href', 'http://stackoverflow.com')

任何解决方案都可以。另外,我开始认为iframe是一种方式。

使用Ajax请求:

$(document).ready(function () {
    // Declare the var
    var num = 0;
    // Function to be called every 5 secs
    var update = function() {
      $.ajax({
        url: '/number.php',
        type: 'get',
        success: function (output) {
            return output;
        }
      });
    };
    // Every 5 secs call update(), check if return a number > 0, and add it to num var
    setInterval(function () {
        var out = update();
        if (out > 0) {
            num += out;
        }
        console.log(num);
    }, 5000);
});