[英]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.