![](/img/trans.png)
[英]How to force mobile browsers to reload the page when the application is reopened
[英]Reload page if tab reopened
如果關閉並在瀏覽器中重新打開選項卡,如何重新加載頁面?
<?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
我該怎么做才能獲得更新的價值?
通常,如果您在很短的時間內重新打開同一頁面,則將從緩存中加載該網頁。 嘗試清除緩存並重新加載。
如果您希望站點始終從服務器加載而不使用緩存。 您可以在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");
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.