强制ajax调用以清除缓存 [英] Force ajax call to clear cache

查看:69
本文介绍了强制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({输入:"POST",异步:是的,网址:"/manage/update_position/",数据:"action ="+ action +"& model ="+模型+"& object_id ="+ object_id +"& position ="+位置,dataType:"json",成功:功能(数据){$(#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);返回false;}); 

解决方案

您拥有

  $("objects-list").html(data ["html"]); 

尝试以下方法:

  $(.objects-list").html(data ["html"]);//忘记了前导点? 

此外,您似乎要用一些包含< table> 元素本身的html替换 .objects-list 表的内容.因此,在替换 .html()内容之后,您需要< table ...>< table ...> 等.

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;
});

解决方案

You have

$("objects-list").html(data["html"]);

Try this instead:

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

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.

这篇关于强制ajax调用以清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆