强制ajax调用清除缓存
我有一个 cms,可以在其中更改对象的位置。每次位置更改后,ajax 调用都会更新整个对象列表。但不幸的是,一些数据存储在缓存中,并且没有可见的更改。有没有办法用 javascript/request/other 强制清除缓存?我已经在 $.ajax
中尝试过“cache: false”,但它不起作用。
这是一个示例页面:
http://ntt.vipserv.org/manage/playforward
和我的js :
$(".object-position").livequery("change", function() {
$("#objects-list input").attr('disabled', true);
var action = $(this).attr('name');
var position = $(this).attr('value');
var id = $(this).attr("id");
var model = id.split("-")[0];
var object_id = id.split("-")[1];
$("#loader").show();
$("#loader").fadeIn(200);
$.ajax({
type: "POST",
async: true,
url: "/manage/update_position/",
data: "action=" + action + "&model=" + model + "&object_id=" + object_id + "&position=" + position,
dataType: "json",
success: function(data){
$("#loader").fadeOut("fast", function () {
$("#loader").hide();
});
$("objects-list").html(data["html"]);
$("#message").show();
$("#message").fadeIn(400).html('<span>'+data["message"]+'</span>');
setTimeout(function(){
$("#message").fadeOut("slow", function () {
$("#message").hide();
});
}, 1500);
}
});
$("#objects-list input").attr("disabled", false);
return false;
});
I have a cms in which I can change positions of objects. After each position change ajax call updates the whole list of objects. But unfortunately some data is stored in cache and no changes are visible. Is there a way to force clearing cache with javascript/request/other ? I've tried 'cache: false' in $.ajax
but it's not working.
Here's a sample page :
http://ntt.vipserv.org/manage/playforward
And my js :
$(".object-position").livequery("change", function() {
$("#objects-list input").attr('disabled', true);
var action = $(this).attr('name');
var position = $(this).attr('value');
var id = $(this).attr("id");
var model = id.split("-")[0];
var object_id = id.split("-")[1];
$("#loader").show();
$("#loader").fadeIn(200);
$.ajax({
type: "POST",
async: true,
url: "/manage/update_position/",
data: "action=" + action + "&model=" + model + "&object_id=" + object_id + "&position=" + position,
dataType: "json",
success: function(data){
$("#loader").fadeOut("fast", function () {
$("#loader").hide();
});
$("objects-list").html(data["html"]);
$("#message").show();
$("#message").fadeIn(400).html('<span>'+data["message"]+'</span>');
setTimeout(function(){
$("#message").fadeOut("slow", function () {
$("#message").hide();
});
}, 1500);
}
});
$("#objects-list input").attr("disabled", false);
return false;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
cache: false
的作用是将时间添加到请求数据中,因此每个请求实际上都是唯一的,因此绕过了浏览器的缓存。我想知道您使用数据字符串而不是对象的事实是否导致了这里的问题。尝试使用一个对象来代替:What
cache: false
does is to add the time to the request data, so each request is effectively unique and therefore bypasses the browser's cache. I wonder if the fact that you are using a data string rather than an object is causing problems here. Try using an object instead:只需替换
为
即可强制重新加载页面,而不使用浏览器的缓存。
Just replace
with
to force reloading the page not using the browser’s cache.
您可以
尝试以下操作:
此外,您似乎正在尝试用一些包含
的 html 替换
.objects-list
表的内容元素本身。因此,在.html()
内容替换之后,您将得到
等。You have
Try this instead:
Also, it looks like you're trying to replace the contents of the
.objects-list
table with some html that includes the<table>
element itself. So you'd have<table...><table...>
, etc., after the.html()
content replacement.