Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 强制ajax调用清除缓存_Jquery_Ajax_Caching_Xmlhttprequest_Clear Cache - Fatal编程技术网

Jquery 强制ajax调用清除缓存

Jquery 强制ajax调用清除缓存,jquery,ajax,caching,xmlhttprequest,clear-cache,Jquery,Ajax,Caching,Xmlhttprequest,Clear Cache,我有一个cms,我可以改变物体的位置。每次位置更改后,ajax调用都会更新整个对象列表。但不幸的是,有些数据存储在缓存中,没有可见的更改。有没有办法用javascript/request/other强制清除缓存?我在$.ajax中尝试了“cache:false”,但它不起作用 以下是一个示例页面: 还有我的js: $(".object-position").livequery("change", function() { $("#objects-list input").attr('d

我有一个cms,我可以改变物体的位置。每次位置更改后,ajax调用都会更新整个对象列表。但不幸的是,有些数据存储在缓存中,没有可见的更改。有没有办法用javascript/request/other强制清除缓存?我在
$.ajax
中尝试了“cache:false”,但它不起作用

以下是一个示例页面:

还有我的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;
});
$(“.object position”).livequery(“change”,function()){
$(“#对象列表输入”).attr('disabled',true);
var action=$(this.attr('name');
var position=$(this.attr('value');
var id=$(this.attr(“id”);
var模型=id.split(“-”[0];
var object_id=id.split(“-”[1];
$(“#加载程序”).show();
$(“#加载器”).fadeIn(200);
$.ajax({
类型:“POST”,
async:true,
url:“/manage/update\u position/”,
数据:“action=“+action+”&model=“+model+”&object_id=“+object_id+”&position=“+position,
数据类型:“json”,
成功:功能(数据){
$(“#加载程序”).fadeOut(“快速”,函数(){
$(“#加载程序”).hide();
});
$(“对象列表”).html(数据[“html]”);
$(“#消息”).show();
$(“#message”).fadeIn(400).html(“”+data[“message”]+“”);
setTimeout(函数(){
$(“#消息”)。淡出(“慢”,函数(){
$(“#消息”).hide();
});
}, 1500); 
}
});
$(“#对象列表输入”).attr(“禁用”,false);
返回false;
});

缓存:false所做的是将时间添加到请求数据中,因此每个请求实际上是唯一的,因此绕过浏览器的缓存。我想知道您使用的是数据字符串而不是对象这一事实是否导致了这里的问题。请尝试改用对象:

$.ajax({
    type: "POST",
    async: true,
    url: "/manage/update_position/",
    data: {
        "action": action.
        "model": model,
        "object_id": object_id,
        "position": position
    },
    cache: false,
    dataType: "json",
    success: function(data){
        //[snip]
    }
});
替换

url: "/manage/update_position/",

强制不使用浏览器缓存重新加载页面。

您有

$("objects-list").html(data["html"]);
请尝试以下方法:

$(".objects-list").html(data["html"]); // forgot leading dot?

另外,看起来您正试图用一些包含
元素本身的html来替换
.objects list
表的内容。因此,在更换
.html()
内容之后,您可能会遇到
等问题。

,这很容易破坏路由系统。如果要手动执行此操作,请将其作为请求参数:
“/manage/update\u position/?nocache=“+Math.random()
是的,您完全正确。我忘了在我原来的帖子中添加一个
“?”
。它应该是:
“/manage/update\u position/?”+Math.random(),
我确认-这确实有效。cache:false将时间戳添加到url,因此每次加载新内容时都会添加时间戳。
$(".objects-list").html(data["html"]); // forgot leading dot?