php - 未使用 php ajax 在引导表上加载数据
问题描述
我正在创建一个简单的 crud 系统,而我加载数据时未加载数据。但我成功地从 all_category.php 中获取了数据。我通过 console.log 检查了
0: {id: 65, catname: "sad", status: 1}
1: {id: 62, catname: "Pepsi", status: 1}
2: {id: 60, catname: "Mobile", status: 1}
到目前为止,我尝试了什么,我在下面附上了代码。我尝试了 2 天,但无法解决这个问题。数据没有传递到表。我附上了下面的屏幕截图
表的形式设计
<table id="tblCenters" data-toggle="table" data-show-refresh="true"
data-show-toggle="true" data-show-columns="true" data-search="true"
data-select-item-name="toolbar1" data-pagination="true" data-sort-name="aid"
data-sort-order="desc">
<thead>
<tr>
<th data-field="catname" data-sortable="true">Category</th>
<th data-field="status" data-sortable="true">Status</th>
<th data-field="opt" data-sortable="true">Edit</th>
</tr>
</thead>
<tr>
</tr>
</table>
jQuery
function get_all() {
$.ajax({
type: 'POST',
url: 'all_category.php',
dataType: 'json',
success: function (data) {
console.log(data);
$('#tblCenters').bootstrapTable('removeAll');
for (var i = 0; i < data.length; i++) {
var btnCell = '<button id="u' + data[i][0] + '" type="button" class="btn btn-success btn-xs" onclick="updateAcc(this)">Edit</button>';
addRow(data[i][1], data[i][2], btnCell);
}
}
,
error: function (data) {
console.log(data);
}
});
function addRow(catname,status,cell) {
$('#tblCenters').bootstrapTable('insertRow', {
index: 1,
row: {
catname: catname,
status:status,
opt:cell
}
});
}
all_category.php
<?php
include("db.php");
$stmt = $conn->prepare("select id,catname,status from category order by id DESC ");
$stmt->bind_result($id,$catname,$status);
if ($stmt->execute()) {
while ( $stmt->fetch() ) {
$output[] = array ("id"=>$id, "catname"=>$catname,"status"=>$status);
}
echo json_encode( $output );
}
$stmt->close();
解决方案
推荐阅读
- visual-studio-code - Visual Studio Code 插件创建指南
- php - 将数据从oracle数据库插入mysql数据库
- python - pandas.read_stata() 错误:解包需要 4 个字节的缓冲区
- c++ - 字符串的拆分
- python - 当 RabbitMQ 消费者闲置一天后,该消费者会被自动移除
- python - 如何在 python 中使用多线程将数据写入文本文件?
- node.js - NGINX 未找到 404 资源未加载
- powershell - 使用 Powershell 比较两个哈希值
- r - R中字符串中间的单词完全匹配
- spring - 为什么 Spring Data Rest 必须扩展 CrudRepository 而不是 Repository?