$ _POST变量为空(使用Ajax)

时间:2018-05-15 09:46:35

标签: php jquery ajax jsgrid

我尝试添加一个标签,在表格中添加一行(在数据库中)。 我使用jsgrid但是我有一个json错误:当我尝试执行PHP时,我的prepare方法有一个错误(在execute函数中使用$ _POST变量)。 我的代码:

switch($_SERVER["REQUEST_METHOD"]) {
    case "POST":
    var_dump($_POST);
    $result= $bdd->prepare('UPDATE t_test SET name=:name, last_name=:last_name WHERE id=:id');
    $result->execute(array(
        'name' => $_POST['name'],
        'last_name' => $_POST['last_name'],
        'id' => $_POST['id'],
        ));
    //var_dump($result);

    // header("Content-Type: application/json");
    // echo json_encode($result); 
break;
}

和js部分:

 <script>
$(function() {

$("#grid").jsGrid({
  height: "70%",
  width: "100%",
  filtering: true,
  editing: true,
  inserting: true,
  sorting: true,
  paging: true,
  autoload: true,

controller: {
            insertItem: function(item) {
                return $.ajax({
                    url: "items.php",
                    type: "POST",
                    contentType : "application/json; charset=utf-8",
                    data: item,
                    dataType: "json",
                });
            },
  })
})

在这里你可以找到the jsgrid documentation 谢谢你的帮助。

错误:

  

SyntaxError:JSON.parse:JSON dataCharge的第1行第1列的意外字符注意

     

未定义的索引: jsgrid \ items.php中的名称 通知

     

未定义索引: jsgrid \ items.php中的last_name 注意
  未定义的索引: jsgrid \ items.php

中的id      

{“queryString”:“UPDATE t_test SET name =:name,last_name =:last_name WHERE id =:id”}

请求:https://framapic.org/tnYXF3o0ZHjz/AumuvhieAYAW.PNG 答案:https://framapic.org/R8BJm7CfHnSl/QDAan6IVKdER.PNG

0 个答案:

没有答案