FancyGrid ajax成功变量未定义

时间:2017-11-22 09:02:00

标签: php jquery ajax

我在将数据库数据发送到客户端表时有点麻烦。我正在使用花式网格。

客户端

        $.ajax({

            url:'function.php?what=listofbookings',
            type:'post',

            data:{user:user},
            success: function(data) {

                var clients = data;
            }

        }); 

        });     

    $("#jsGrid").jsGrid({
    width: "100%",
    height: "400px",

    inserting: true,
    editing: true,
    sorting: true,
    paging: true,

    data: clients,

    fields: [
        { name: "people", type: "text", width: 150, validate: "required" },
        { name: "email", type: "number", width: 50 }

    ]
});

这是PHP代码

if(isset($_GET['what'])){
  if($_GET['what'] === 'listofbookings'){

  $selit = "SELECT * FROM dbdbdb_booking";
    $queryit = mysqli_query($conn,$selit);
    $arr = array();
    while($row = mysqli_fetch_assoc($queryit)){

        $arr[] = $row;


    }


echo json_encode($arr);
  }
 }

由于某种原因,未定义var客户端,并且数据未传递给客户端。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您需要在AJAX的成功中初始化jsGrid:

$.ajax({
    url:'function.php?what=listofbookings',
    type:'post',
    data:{user:user},
    success: function(data) {
        var clients = data;
        $("#jsGrid").jsGrid({
            width: "100%",
            height: "400px",
            inserting: true,
            editing: true,
            sorting: true,
            paging: true,
            data: clients,
            fields: [
                { name: "people", type: "text", width: 150, validate: "required" },
                { name: "email", type: "number", width: 50 }
            ]
        });
    }
});