简体   繁体   English

如何在引导选项卡中禁用缓存ajax加载内容

[英]How to disable caching in bootstrap tabs ajax load content

I am trying to enable bootstrap tabs to load content by ajax query. 我正在尝试启用引导选项卡以通过ajax查询加载内容。 this is straight forward with Jquery tabs which is default loads the content with ajax query. 这是直接使用Jquery选项卡,默认情况下使用ajax查询加载内容。

I assume that this is not the case in bootstrap 我假设在bootstrap中不是这种情况

Therefore I have found the code below to work with 因此,我发现下面的代码可以使用

 $('#myTabs a').click(function (e) {
    e.preventDefault();

    var url = $(this).attr("data-url");
    var href = this.hash;
    var pane = $(this);

    // ajax load from data-url
    $(href).load(url, function (result) {
        pane.tab('show');
    });
});

This is working fine only once and caches the content of the tab and never sends another ajax query back to server. 这只能正常工作一次并缓存选项卡的内容,并且永远不会将另一个ajax查询发送回服务器。 I would like to somehow disable caching and send request every time the tab is clicked. 我想以某种方式禁用缓存并在每次单击选项卡时发送请求。 I assume somewhere I have to say cache : false but not sure exactly where it should go? 我假设某个地方我不得不说缓存:false但不确定它到底应该去哪里?

Just add a unique timestamp to each request to foil jQuery's caching mechanism: 只需为每个请求添加一个唯一的时间戳,以阻止jQuery的缓存机制:

var ts = +new Date();
var url = $(this).attr("data-url") + '?timestamp='+ts;

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM