簡體   English   中英

從查詢到SQL數據庫的結果在刪除臨時Internet文件之前不會顯示

[英]Results from query to SQL database not showing until temporary internet files deleted

我有兩個網頁。 第一個允許用戶更改老師所屬的部門。 按鈕上的操作將調用php文件,該文件發送所需的SQL命令,並且信息已正確添加到SQL數據庫。

第一頁

然后第二個顯示兩個下拉框。 選擇部門后,第二個下拉列表將列出該部門的教師。

webpage2

要獲取此數據,我使用:

<script type="text/javascript">
function checkTeacherList(departmentName, schoolName) 
{
var xmlhttp;

if (departmentName=="All")
  {
//  document.getElementById("departmentTeachers").innerHTML="";
    $("#departmentTeachers").hide(0);
    $("#allTeacherList").show(0);
  return;
  }
 else
{ 
    $("#departmentTeachers").show(0);
    $("#allTeacherList").hide(0);

} 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("departmentTeachers").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://localhost/iobserve/php/getTeachers.php?schoolName="+schoolName+"&departmentName="+departmentName,true);
xmlhttp.send();

如果我從第一頁將教師添加到某個部門,則如果我手動刪除Internet臨時文件,它只會顯示在第二頁中。

我知道正在緩存舊數據,但是我不確定如何強制重新加載以便正確顯示數據?

一種方法是像當前時間一樣向查詢字符串添加隨機值

var d = new Date();
xmlhttp.open("GET","http://localhost/iobserve/php/getTeachers.php?schoolName="+schoolName+"&departmentName="+departmentName+"&nocache="+d.getSeconds(),true);
xmlhttp.send();

或設置標題

 xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2005 00:00:00 GMT");

或在服務器端設置緩存頭

 header("Expires: Sat, 1 Jan 2005 00:00:00 GMT");
 header("Last-Modified: ".gmdate( "D, d M Y H:i:s")."GMT");
 header("Cache-Control: no-cache, must-revalidate");
 header("Pragma: no-cache");

控制緩存

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM