$_POST variable empty (with Ajax)

24
May 15, 2018, at 8:00 PM

I've tried to add a lign a tab which add a row in a table (in database). I use jsgrid but I've a json error : when I try to execute PHP, I have an error on my prepare method (with the $_POST variable in the execute function). My code :

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;
}

And the js part :

 <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",
                });
            },
  })
})

Here you can find the jsgrid documentation Thanks for your help.

The error :

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON dataCharge Notice:

Undefined index: name in jsgrid\items.php Notice:

Undefined index: last_name in jsgrid\items.php Notice:
Undefined index: id in jsgrid\items.php

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

The request : https://framapic.org/tnYXF3o0ZHjz/AumuvhieAYAW.PNG The answer : https://framapic.org/R8BJm7CfHnSl/QDAan6IVKdER.PNG

READ ALSO
Outputting javascript array values in a for loop results in undefined

Outputting javascript array values in a for loop results in undefined

I'm trying to use a loop to output values from two arrays on a jQuery hover functionOutside of the hover, I can access these array values fine but inside I get undefined

21
How to create regex to satisfy this condition &ldquo;At least 1 letter and at least 1 number or symbol.&rdquo; [on hold]

How to create regex to satisfy this condition “At least 1 letter and at least 1 number or symbol.” [on hold]

How to create regex to satisfy this condition "At least 1 letter and (at least 1 number or symbol)"

12
How to import Bootstrap 4 theme in Angular 4 or 4+ app

How to import Bootstrap 4 theme in Angular 4 or 4+ app

I'm new in learning AngularI have tried to import bootstrap 4 single page template in angular 4 This one: https://startbootstrap

60
find img tag by src value and add new attribute in img tag

find img tag by src value and add new attribute in img tag

If I have 5 images into the HTML pageI want to search 2 images by it's src attribute value and add a new attribute to the image tag

50