How to use AJAX loading with Bootstrap tabs?

后端 未结 10 1635
無奈伤痛
無奈伤痛 2020-12-02 08:30

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 load

10条回答
  •  一个人的身影
    2020-12-02 08:49

    Here is a solution I have found - and modified to suit my needs:

    $("#tabletabs").tab(); // initialize tabs
    $("#tabletabs").bind("show", function(e) { 
    var contentID = $(e.target).attr("data-target");
    var contentURL = $(e.target).attr("href");
    if (typeof(contentURL) != 'undefined') { // Check if URL exists
    $(contentID).load(contentURL, function(){
    $("#tabletabs").tab(); // reinitialize tabs
    });
    } else {
    $(contentID).tab('show');
    }
    });
    $('#tabletabs a:first').tab("show"); // Load and display content for first tab
    });
    

提交回复
热议问题