简体   繁体   English

表行未显示在 tbody 标记内

[英]Table Rows are not shown inside the tbody tag

I am looking to insert rows to the table but The rows are echoed but not displayed inside the table.我正在寻找向表中插入行但行被回显但未显示在表内。

The HTML code of the project is:该项目的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>

The main.js file of the project is: It fetches data from the PHP file below:该项目的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 code of the project is: 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(); }
}?>

Try appending data (insted of html ) like so:尝试像这样附加数据( html ):

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

note: check in the console that your php code is returning valid html ( <tr> data)注意:在控制台中检查您的 php 代码是否返回有效的 html( <tr>数据)

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

相关问题 带有垂直滚动的程式化HTML表格 - Stylized HTML table with vertical scroll inside tbody 如何摆脱和 HTML 表标签但不删除标签内的内容? - How To Get Rid Of <tbody> and </tbody> HTML Table Tags But Not Remove The Content Inside The Tags? 表格行在其中不可见 <tbody> 。 该表中如何实现搜索过滤器? - Table rows not visible within <tbody>. How could search filter be implemented in this table? 表格:仅显示表格正文的第一行。 如何隐藏后续的第一行? - Table: Show only the first row of table tbody. How to hide the succeeding 1st rows? 从包含特定 tbody 标记内特定 class 的多个表格单元格中抓取值 - Scraping values from multiple table cells that contain a specific class within a specific tbody tag 尝试通过Jquery和目标div标记在表中输出行循环 - Trying to output a loop of rows inside a table via Jquery and a target div tag 无法放一个 <table> div标签内的标签 - unable to put a <table> tag inside a div tag 如何隐藏基于先前搜索显示的先前表行 - How to hide previous table rows that were shown based on previous search 在表单发布错误后保持显示动态表行 - Keeping Dynamic Table Rows shown after form post errors 日期字段的行未显示在杂货杂货表中 - Date field's rows are not shown in the grocery crud table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM