assaqqaf assaqqaf - 1 month ago 13
Ajax Question

How to use AJAX loading with Bootstrap tabs?

I used bootstrap-tabs.js and it has worked perfectly.

But I didn't find information about how to load content through AJAX request.

So, how to use AJAX loading with bootstrap-tabs.js?

Answer

You can listen the change event and ajax load content in the event handler

$('.tabs').bind('change', function (e) {
    var now_tab = e.target // activated tab

    // get the div's id
    var divid = $(now_tab).attr('href').substr(1);

    $.getJSON('xxx.php').success(function(data){
        $("#"+divid).text(data.msg);
    });
})