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