How to use AJAX loading with Bootstrap tabs?

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

    There is an error in your code user1177811.

    It has to be $('[data-toggle="tabajax"]').

    Also there is room for improvement. The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. So i added #content to load the content div of the remote page.

    $this.tab('show'); is now only called, when response was a success.

    Here is the code

     $('[data-toggle="tabajax"]').click(function(e) {
            e.preventDefault();
            $this = $(this);
            var loadurl = $(this).attr('href');
            var targ = $(this).attr('data-target');
            $(targ).load(loadurl+'?ajax=true #content', function(){
                $this.tab('show');
            });
        });
    

提交回复
热议问题