dongxing4805 2019-05-16 10:30
浏览 84

如何在Ajax Jquery内部打开或显示Nav-Tab成功?

What I'm doing is - I have a three nav-tabs in my index.php, two nav-tabs can be directly access by clicking it, But one tab in the middle can't be easily access without entering the user's PIN for authentication.

My problem is the Admin-tab in the middle only show once when Ajax success was triggered successfully. And the other tabs (customer,history) is also showing its tab-contents inside the admin-tab.

1. How can I show/open the admin-tab every time I successfully verified my PIN thru AJAX success?

2. How can I prevent the content of Customer and History tab appearing on the admin-tab?

Here's the code I did but having a problem, I would appreciate any help, Thank you in advance :)

    <!DOCTYPE html>
     <html>
     <head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <title>Find Date and Time</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<title>Open Nav-Tab</title>
    </head>
    <body>
<div class = "container">
    <ul class = "nav nav-tabs">
        <li class = "nav-item"><a href = "#customer" data-toggle = "tab" class = "nav-link active">Customer</a></li>
        <li class = "nav-item"><a href = "#enterPinModal" data-toggle = "modal" class = "nav-link">Admin</a></li>
        <li class = "nav-item"><a href = "#history" data-toggle = "tab"class = "nav-link">History</a></li>
    </ul>
    <div class = "tab-content">
        <div class = "tab-pane container active" id = "customer">
            <br><br>Show Customer Information
        </div>
        <div class = "tab-pane container" id = "admin">
            <br><br>Show Enter Pin Modal first for authetication before showing Admin Information
        </div>
        <div class = "tab-pane container" id = "history">
            <br><br>Show History here
        </div>      
    </div>  
    <!-- ENTER PIN MODAL -->
    <div class = "modal" id = "enterPinModal">
        <div class = "modal-dialog">
            <div class = "modal-content">
                <div class = "modal-header">
                    <h5 class = "modal-title">Security Confirmation</h5>
                    <button class = "close" data-dismiss = "modal">&times;</button>
                </div>
                <div class = "modal-body">
                    <label class = "font-weight-bold">PIN #:</label>
                    <input type = "password" maxlength = "6" id = "pin_no" class = "form-control" />
                </div>
                <div class = "modal-footer">
                    <button id = "submit_pin" class = "btn btn-success btn-sm">Submit</button>
                    <button class = "btn btn-danger btn-sm" data-dismiss = "modal">Close</button>
                </div>
            </div>
        </div>
    </div>

</div>
    </body>
    </html>

Ajax

<script>
$("#submit_pin").click(function () {

    var pin = $("#pin_no").val();

    $.ajax({
        url: "pin_verify.php",
        type: "post",
        data: {
            pin_number: pin
        },
        success: function(data) {
            $('#admin').show();
            $('#enterPinModal').modal('hide');
        }
    });
});
</script>

PHP

  <?php
  $cn = mysqli_connect("localhost","root","","testdb");
  $pin = $_POST['pin_number'];

  $sql = "SELECT * FROM tblPin WHERE pin = '$pin'";
  $result = mysqli_query($cn,$sql);

  ?>
  • 写回答

2条回答

  • douzhanglun4482 2019-05-16 10:33
    关注

    just .show() will show the tab. your code inside ajax for showing admin tab is wrong.

    $('#admin').show();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建