仅在正确的选项卡中显示ajax调用后的信息

时间:2017-08-10 02:28:22

标签: javascript php jquery ajax tabs

我有jquery标签。每个选项卡名称都取自数据库:

<div id="tabs">
<ul>
<?php
$hod_result = getFamilyTree();
$i = 0;
while($hod_row = mysqli_fetch_array($hod_result))
{
?>
    <li>
        <a href="#<?php echo $hod_row["staff_id"]?>" ><span class="closer" data-id3="<?php echo $hod_row["staff_id"] ?>">x</span><?php echo $hod_row["longname"].' ('.$hod_row["team_role"].')' ?></a>              
    </li>
<?php $i++;} ?>
</ul>
<?php
$hod_result_tabs = getFamilyTree();
$i_tabs = 0;
while($hod_row_tabs = mysqli_fetch_array($hod_result_tabs))
{    
?>    
  <div id="<?php echo $hod_row_tabs["staff_id"]?>">
    <!--<div class="test"></div>-->
    <div class="tree" id="<?php echo $hod_row_tabs["staff_id"]?>"> 
    <ul>
    <li>
    <?php
    $hod_id_list = $hod_row_tabs["staff_id"];
    $sv_result_list= getSupervisorRole($hod_id_list);
    ?>
    <a href="#">
        <table>
        <tr>
            <th colspan="3">Head Of The Department:</th>    
        </tr>
        <tr>
            <td>
                <a href="#" style="background-color:#808080; color:white; font-size: 8px; padding: 3px 3px 3px 3px;"><?php echo substr($hod_row_tabs["team_role"], 0, 3); ?></a>
                <span class="closer" data-id3="<?php echo $hod_row_tabs["staff_id"]; ?>">x</span>
                <?php echo $hod_row_tabs["staff_id"].' '.$hod_row_tabs["username"]; ?>
                <span class="create-user" data-id3="<?php echo $hod_row_tabs["staff_id"].'|Supervisor';?>"><img alt="" src="imagesAssessment/add.png"></span>
                <span class="btn_details" data-id3="<?php echo $hod_row_tabs["staff_id"]; ?>"> <img title="View Evaluation Details" src="imagesAssessment/details.png"></span>
            </td>            
        </tr>
        </table>
    </a>
        <ul>
        <?php
        $sv_result= getSupervisorRole($hod_id_list);
        if(mysqli_num_rows($sv_result) > 0){
            while($sv_row = mysqli_fetch_array($sv_result))
            {
        ?>
        <li>
            <a href="#" >
                <table style='all:unset;'>
                <tr>
                    <td>
                        <a href="#" style="background-color:#808080; color:white; font-size: 8px; padding: 3px 3px 3px 3px;"><?php echo strtoupper(substr($sv_row["team_role"], 0, 3)); ?></a>
                        <span class="closer" data-id3="<?php echo $sv_row["staff_id"]; ?>">x</span>
                        <a href="#" style='all:unset;' class="expand" data-id3="<?php echo $sv_row["staff_id"].'|'.$sv_row["username"].'|'.$sv_row["importance"]; ?>">
                        <?php echo $sv_row["username"]; ?> 
                        </a>
                    </td>
                </tr>                        
                <tr>
                    <td>
                        <?php echo $sv_row["staff_id"]; ?> 
                        <span class="create-user" data-id3="<?php echo $sv_row["staff_id"].'|Checker'; ?>"><img alt="" src="imagesAssessment/add.png"></span>
                        <span class="btn_details" data-id3="<?php echo $sv_row["staff_id"]; ?>"> <img title="View Evaluation Details" src="imagesAssessment/details.png"></span>
                    </td>
                </tr>
                </table>
            </a>

        </li>
        <?php }} ?>
        </ul>
    </li>
    </ul>
    </div>
    <div class="input"></div>
  </div>
<?php $i_tabs++;} ?>
</div>

最多可以有10个标签,具体取决于表格中有多少用户。因此,当我想通过点击<a href="#" style='all:unset;' class="expand" data-id3="<?php echo $sv_row["staff_id"].'|'.$sv_row["username"].'|'.$sv_row["importance"]; ?>"><?php echo $sv_row["username"]; ?> </a>

扩展用户并查看更多信息时

点击链接,我打电话给ajax:

$(document).on('click', '.expand', function(){
    var view_current = $(this).data("id3");
    $.ajax({
        url: "comAssessment/hr_tree_selected.php",
        method: "POST",
        data: {view_current: view_current},
        dataType:"text",
        success: function (data) {
            $('.tree').html(data).slideDown("slow");
        }
    });
});

我想将收到的信息从ajax显示到当前标签。但问题是每个选项卡中都会显示信息。它只是替换每个选项卡中的信息。我该如何解决这个问题?

以下是一些可以更好理解的图片: 有两个标签:enter image description here enter image description here

然后我点击一个名称展开它,这就是我得到的。信息替换两个标签:enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

你可以试试这个。

async Download()