![](/img/trans.png)
[英]The response.setheader on a java servlet does not disable browser cache
[英]jquery and jsp - still saving in cache even cache:false and response.setHeader(“Cache-Control”, “no-cache”)
我有個問題。 將代碼放在jsp上之后,我仍然可以看到緩存仍在增加。
<% response.setHeader("Cache-Control", "no-cache"); %>
並在我的javascript / jquery中(位於同一jsp上):
function waitForMsg() {
$.ajax({
type: "GET",
url : contextPath + "/groupChat",
async: true,
cache: false,
success: function (data) {
$("#divChatMessageTable").load(contextPath + "/groupChat/message");
setTimeout(waitForMsg, 1000);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
setTimeout(waitForMsg, 15000);
}
});
if ($("#divChatMessageTable").height() > tableHeight) {
scrollToBottomChat ();
tableHeight = $("#divChatMessageTable").height();
}
}
我已經在jquery中設置了cache:false
。
順便說一句,我正在使用Firefox。
請幫忙。
您可能會擺脫最初的ajax調用,而只需保留load
調用(也是ajax)。 下面的一個區別是將成功回調添加到load
方法,因此您無需在插入新內容之前測試其高度
function waitForMsg() {
$("#divChatMessageTable").load(contextPath + "/groupChat/message", function({
/* new content now exists*/
if($("#divChatMessageTable").height() > tableHeight) {
scrollToBottomChat();
tableHeight = $("#divChatMessageTable").height();
}
setTimeout(waitForMsg, 1000);
});
}
load
API刷新http://api.jquery.com/load/
我已經通過添加no-store, must-revalidate
解決了這個問題。
編碼:
<% response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.