在同一台服务器上从另一个页面手动刷新页面

Manually refresh page from another page, on the same server

我正在尝试使用代码将 PHP 文件中的 MySQL 标志设置为真(假设为 A)。我想从另一个已经打开的 PHP 文件 (B) 中读取这个 MySQL 标志。问题是:从第一页(A)更改标志值后,是否有任何方法可以手动刷新此(B)页面?

可能正在使用 cron 或类似的东西,我真的不想每 X 秒刷新一次页面 B,直到它读取新的标志值。

使用AJAX。

在 B 页面内创建一个请求函数来检查 MySQL 标志的状态。如果标志设置为true,刷新页面。

在B程序的HTML中插入:

<head>
...
  <script>
    function enableChecker() {
        setInterval( checkFlag, 10000); // Check each ten seconds
    }

    function checkFlag() {
        xmlhttp = GetXmlHttpObject();
        if ( xmlhttp==null ) return;
        xmlhttp.onreadystatechange = function() {
            if ( xmlhttp.readyState == 4 ) {
                if ( xmlhttp.responseText == "OK" ) {
                    location.reload(); // Refresh the page
                }
            }
        }
        xmlhttp.open( 'GET', 'myCheckProgram.php', true ); // Call php program to check the flag value
        xmlhttp.send( null );
        return false;
    }
  </script>
</head>
<body onload="enableChecker()" >

创建名为 myCheckProgram.php

的程序
<?php

/* Blah blah to connect with database and query for flag */

$flag = // Result of query

echo $flag ? 'OK' : 'NOK' // Return OK if flag is true

?>