如果重新打开选项卡,请重新加载页面

时间:2017-01-01 15:25:09

标签: javascript php jquery html browser

如果选项卡已关闭并在浏览器中重新打开,如何重新加载页面?

<?php
    $sql = "SELECT x FROM users WHERE id='1' LIMIT 1";
    $query = mysqli_query($connect, $sql);
    $row = mysqli_fetch_row($query);
    $x = $row[0];

    // value for x here is 50

    $sql = "UPDATE users SET x='100' WHERE id='1'";
    $query = mysqli_query($connect, $sql);
?>
<!doctype html>
<html>
    <head>
        <title>Page Title</title>
    </head>
    <body>
        <p>Page content</p>
        <script>
            alert('<?php echo $x; ?>');
        </script>
    </body>
</html>

首先警告说50

然后按 Ctrl + W

关闭标签

然后当我按 Ctrl + Shift + T 重新打开标签时,警报再次显示50而不是100

如何获取更新后的价值?

1 个答案:

答案 0 :(得分:3)

通常,如果您在很短的时间内重新打开同一页面,网页将从缓存中加载。尝试清除缓存并重新加载。

如果您希望始终从服务器加载您的站点而不使用缓存。您可以在PHP脚本中添加以下内容。但是不要使用它,除非这是非常必要的,因为缓存机制已经到位以改善用户体验。

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
相关问题