简体   繁体   English

如何使用 Ajax 从另一个页面操作引导选项卡

[英]How to manipulate Bootstrap tabs from another page using Ajax

I have a view in my Laravel project that shows all products in the first tab and pending products in the second tab.我在我的 Laravel 项目中有一个视图,该视图在第一个选项卡中显示所有产品,在第二个选项卡中显示待定产品。 in the second tab when I enter to validate a certain product, I am redirected to my view whose first tab is active, and it is really a waste of time to press the second tab every time I am redirected towards my view in order to access a certain product on-hold.在第二个选项卡中,当我输入以验证某个产品时,我被重定向到我的第一个选项卡处于活动状态的视图,每次我被重定向到我的视图以便访问时按第二个选项卡确实是浪费时间某个产品被搁置。

So I want the second tab to be activated when I get redirected,how can i achieve this in my ajax success function, here is my script located in the modification view this script has the goal to refuse or accept the product in order for it to show with all the products in my first view which contains the tab:所以我希望在我被重定向时激活第二个选项卡,我如何在我的 ajax 成功 function 中实现这一点,这是我位于修改视图中的脚本,该脚本的目标是拒绝或接受产品以使其在包含选项卡的第一个视图中显示所有产品:

<script type="text/javascript">

    $(".Visibilite").click(function (e) {
           e.preventDefault();
           var ele = $(this);
            $.ajax({
                url: '{{ url('change-visibility') }}',
                method: "post",
                cache: false,
                data: {_token: '{{ csrf_token() }}', produit_id: ele.attr("data-id"), status: ele.attr("data-status")},
                success:function(data) {
                   window.location.replace('{{ url("NouveauProduits") }}');
                }
            });
        });
</script>

and my tab structure:和我的标签结构:

                                <li class="nav-item">
                                    <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" aria-controls="home" aria-expanded="true">
                                        Tous les produits <i class="la la-list-alt"></i>
                                    </a>
                                </li>
                                
                                <li class="nav-item">
                                    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" aria-controls="profile" aria-expanded="false">
                                        Noueaux produits  <i class="ficon ft-bell bell-shake"></i>  <span class="badge badge-pill badge-glow badge-danger float-right">@if ($unvisible->count()>0) {{ $unvisible->count() }} @endif</span>
                                    </a>
                                </li>
                    
                                

in redirected page:在重定向页面中:

If you are using bootstrap 4.x you can switch to that tab programmatically如果您使用的是 bootstrap 4.x,您可以以编程方式切换到该选项卡

$(function () {
    $('#myTab a[href="#profile"]').tab('show')
  })

bootstrap 5.x引导程序 5.x

 var firstTabEl = document.querySelector('#myTab a[href="#profile"]')
 var firstTab = new bootstrap.Tab(firstTabEl)
 firstTab.show()

// Or 
 var firstTab = new bootstrap.Tab($('#myTab a[href="#profile"]'))
 firstTab.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM