首页 > 解决方案 > 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();

标签: phpjson

解决方案


推荐阅读