How to use AJAX loading with Bootstrap tabs?

后端 未结 10 1596
無奈伤痛
無奈伤痛 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:48

    I use this function and it's really nice because she prevent's you from load ajax again when going back to that tab.

    Tip: on tab href, just put the destination. Add this to footer:

    $("#templates_tabs").tabs({
        beforeLoad: function( event, ui ) {
          if (ui.tab.data("loaded")) {
              event.preventDefault();
    
              return;
          }
    
    
          ui.ajaxSettings.cache = false,
          ui.jqXHR.success(function() {
    
              ui.tab.data( "loaded", true );
          }),
          ui.jqXHR.error(function () {
    
    
              ui.panel.html(
              "Not possible to load. Are you connected?");
          });
        }
      });
    

提交回复
热议问题