jQuery的AJAX缓存动作禁止不工作? [英] jQuery ajax cache disabling not working?
问题描述
我正在开发一个使用AJAX请求来检索信息的Firefox扩展。这是code:
I'm developing a Firefox extension that uses an ajax-request to retrieve information. This is the code:
$.ajax({
url: "http://127.0.0.1/foo/bar/Service?wsdl" + new Date().getTime(),
beforeSend: function(request) { request.setRequestHeader("SOAPAction", "Group"); },
async: false,
cache: false,
type: "POST",
dataType: "xml",
data: req,
contentType: "text/xml; charset=\"utf-8\"",
success: function (data, textStatus, xmlHttpRequest) {
out = $(xmlHttpRequest.responseXML);
}
});
我仍然得到同样的结果,当被发送到服务器的数据被改变。我试图避免通过添加到URL和缓存:假,新的日期()的getTime()。这似乎并没有工作。重新启动浏览器后,我得到正确的结果。
I still get the same result, when the data that is sent to the server is changed. I tried to avoid that by adding "new Date().getTime()" to the URL and "cache: false". This doesn't seem to work. After restarting the browser, I get the correct results.
有没有人有一个想法是什么问题? 是否有某种形式的会话处理,因此服务器还是还给旧响应?
Does anyone have an idea what the problem is? Is there some kind of session-handling, so the server still gives back the old response?
编辑:我做了很多的测试和调试的,我想我发现了问题:有那么每一次我再来一次的要求保存每个AJAX请求包含会话ID的Cookie,服务器发送与会话ID cookie中的会话数据。非常糟糕的行为,我不知道饼干可以通过一个Ajax请求创建。 所以,我的一切都做的来解决这个问题是一个功能,我的每一个参数变化时,删除这个cookie。感谢您的再次帮助。
I did a lot of testing and debugging and I think I found the problem: there is a cookie saved with every ajax-request that contains a session-id, so every time I do the request again, the server sends data of the session with the session-id in the cookie. Really bad behavior, I didn't know that cookies could be created through an ajax-request. So everything I have to do to fix the problem is a function that deletes this cookie every time my parameters are changed. Thanks for your help again.
推荐答案
您可以试试这个
$(document).ready(function() {
$.ajaxSetup({ cache: false });
});
试toger用的Math.random()是在安全侧
try toger with Math.random() to be on safer side
日期()的getTime()一起的Math.random()
Date().getTime() together with Math.random()
http://127.0.0.1/foo/bar/Service?wsdl" + new Date().getTime() + Math.random()
这篇关于jQuery的AJAX缓存动作禁止不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!