akd
akd

Reputation: 6758

How to disable caching in bootstrap tabs ajax load content

I am trying to enable bootstrap tabs to load content by ajax query. this is straight forward with Jquery tabs which is default loads the content with ajax query.

I assume that this is not the case in 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. 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?

Upvotes: 1

Views: 2680

Answers (1)

Rob M.
Rob M.

Reputation: 36511

Just add a unique timestamp to each request to foil jQuery's caching mechanism:

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

...

Upvotes: 4

Related Questions