php - bootgrid使用json数据不加载php mysqli
问题描述
我正在尝试将数据与两个按钮编辑和删除一起加载到引导网格中。但是数据没有加载。到目前为止我尝试了什么,现在我附上了下面的代码。如何使用 json get_data.php 页面加载数据。有人可以更正代码吗?我在过去 3 天尝试了这个。我无法得到结果
桌子
<table id="grid-basic" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="id" >Project Name</th>
<th data-column-id="sender">Project Description</th>
<th data-column-id="received" data-order="desc">Project Client</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
jQuery
<script>
var grid = $("#grid-basic").bootgrid({
ajax: true,
post: function ()
{
return {
id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
};
},
url: "get_data.php",
formatters: {
"commands": function(column, row)
{
return
"<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.id + "\"><span class=\"fa fa-pencil\"></span></button> " +
"<button type=\"button\" class=\"btn btn-xs btn-default command-delete\" data-row-id=\"" + row.id + "\"><span class=\"fa fa-trash-o\"></span></button>";
}
}
}).on("loaded.rs.jquery.bootgrid", function()
{
/* Executes after data is loaded and rendered */
grid.find(".command-edit").on("click", function(e)
{
alert("You pressed edit on row: " + $(this).data("row-id"));
}).end().find(".command-delete").on("click", function(e)
{
alert("You pressed delete on row: " + $(this).data("row-id"));
});
});
// $("#grid-basic").bootgrid();
</script>
获取数据.php
<?php
$conn = mysqli_connect("localhost", "root", "", "crudphp");
$query ="SELECT * FROM records ORDER BY id DESC";
$stmt = $conn->prepare("SELECT * FROM records ORDER BY id DESC ");
$stmt->bind_result($id,$project_name,$project_description,$project_client);
if ($stmt->execute()) {
while ( $stmt->fetch() ) {
$output[] = array ("id"=>$id,"project_name"=>$project_name,"project_description"=>$project_description,"project_client"=>$project_client);
$output = $output[] = $output["current"] = 1; $output['rowCount'] = 10;
}
echo json_encode( $output );
}
$stmt->close();
解决方案
推荐阅读
- binary-search-tree - 数据结构
- ios - 如何更改此已弃用的代码?(flutter_inappwebview)
- python - 如何在 python 中生成孟加拉语文本的 wordcloud?
- javascript - 在ndoejs和mongoose中保存数据库后返回数据时调用socket
- java - Java - 替换所有重音符号,但保留版权、商标和注册等符号
- swift - 创建自己的/自定义的类对象
- scala - 在scala中读取多行作为输入
- spring-data-jdbc - 如何在 spring-data-jdbc 中指定表模式
- ios - 使用 rx 在 collectionView 中单击时如何获取我的单元格?
- c - 查找二维数组中每列的元素数