提问者:小点点

tbody标记中不显示表行


我希望将行插入到表中,但这些行被回显,但没有显示在表中。

项目的HTML代码为:

<div class="container">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>SN</th>
                <th>Category</th>
                <th>Parent</th>
                <th>Status</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody id="displayCategory">               
            </tbody>
        </table>
</div>

项目的main.js文件是:它从下面的PHP文件中取数据:

$(document).ready(function () {
manageCategory();
function manageCategory(){
    
    $.ajax({
      url: DOMAIN + "/includes/process.php",
      method: "POST",
      data: { manageCategory: 1 },
      success: function (data) {
        $("#displayCategory").html(data);
        alert(data);
        console.log(data);
      }
    })
  };
}

项目的PHP代码是:

<?PHP
if (isset($_POST["manageCategory"])) {
    $m = new Manage();
    $result = $m->manageTableWithPagination('pdcts_categories', 1);
    $rows = $result['rows'];
    $pagination = $result['pagination'];
    if (count($rows) > 0) {
        foreach ($rows as $row) {
            $n = 0;
            ?>
                <tr>
                    <td><?php echo ++$n; ?></td>
                    <td><?php echo $row["Category"]; ?></td>
                    <td><?php echo $row["Parent"]; ?></td> 
                    <td>
                        <a href="#" class="btn btn-success btn-sm"> Active </a>
                    </td>
                    <td>
                        <a href="#" class="btn btn-info btn-sm"> Edit </a>
                        <a href="#" class="btn btn-danger btn-sm"> Delete </a>
                    </td>
                </tr>
            <?php
        }?>
        <!-- <tr><td colspan="5"><?php echo $pagination; ?></td></tr> -->
    <?php exit(); }
}?>

共1个答案

匿名用户

尝试附加数据(包含HTML),如下所示:

$("#displayCategory").append(data);

注意:请在控制台中检查php代码是否返回有效的html(数据)