jTables не может добавлять, обновлять и удалять

Я практикую использовать jTables Php Sample и меняю его на mysqli. Данные успешно загружены в таблицу, но при добавлении, обновлении и удалении я получаю сообщение об ошибке: «Произошла ошибка при обмене данными с сервером».сообщение об ошибке
PersonActionsPagedSorted.php

<?php

try
{
//Open database connection

/* Database connection start */
$con=mysqli_connect("localhost","root","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


mysqli_select_db($con,"jtabletestdb");




//Getting records (listAction)
if(isset($_GET["action"]) || "list")
{
//Get record count
$sql = "SELECT COUNT(PersonId) AS RecordCount FROM people;";
$result = mysqli_query($con, $sql) or die("error to fetch employees data");

$row = mysqli_fetch_assoc($result);
$recordCount = $row['RecordCount'];

//Get records from database
$sql = "SELECT * FROM people ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";";


$result = mysqli_query($con, $sql)or die("error to sort table data");
//Add all records to an array
$rows = array();
while($row = mysqli_fetch_array($result))
{
$rows[] = $row;
}

//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;

print json_encode($jTableResult);
}

//Creating a new record (createAction)
else if(isset($_GET["action"]) || "create")
{
//Insert record into database
$sql = "INSERT INTO people(Name, Age, RecordDate) VALUES('" . $_POST["Name"] . "', '" . $_POST["Age"] . "',now());";

$result = mysqli_query($con, $sql);

//Get last inserted record (to return to jTable)
$sql = "SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();";

$result = mysqli_query($con, $sql) or die("error to insert new data");

$row = mysqli_fetch_array($result);

//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}

//Updating a record (updateAction)
else if(isset($_GET["action"]) || "update")
{
//Update record in database
$result = mysqli_query("UPDATE people SET Name = '" . $_POST["Name"] . "', Age = " . $_POST["Age"] . " WHERE PersonId = " . $_POST["PersonId"] . ";");

//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}

//Deleting a record (deleteAction)
else if(isset($_GET["action"]) || "delete")
{
//Delete from database
$sql = "DELETE FROM people WHERE PersonId = " . $_POST["PersonId"] . ";";
$result = mysqli_query($con, $sql) or die("error to sort table data");

//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}

//Close database connection
mysqli_close($con);

}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}

?>

jTableSimplePagedSorted.php

<html>
<head>

<link href="themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<link href="Scripts/jtable/themes/metro/green/jtable.css" rel="stylesheet" type="text/css" />

<script src="scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="Scripts/jtable/jquery.jtable.js" type="text/javascript"></script>

</head>
<body>
<div id="PeopleTableContainer" style="width: 600px;"></div>
<script type="text/javascript">

$(document).ready(function () {

//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Table of people',
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'Name ASC',
actions: {
listAction: 'PersonActionsPagedSorted.php?action=list',
createAction: 'PersonActionsPagedSorted.php?action=create',
updateAction: 'PersonActionsPagedSorted.php?action=update',
deleteAction: 'PersonActionsPagedSorted.php?action=delete'
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Author Name',
width: '40%'
},
Age: {
title: 'Age',
width: '20%'
},
RecordDate: {
title: 'Record date',
width: '30%',
type: 'date',
create: false,
edit: false
}
}
});

//Load person list from server
$('#PeopleTableContainer').jtable('load');

});

</script>

</body>
</html>

Я получил сообщение об ошибке, и я не знаю, где это пошло не так. Когда я проверил, я не могу отладить. Также нет ошибки при запуске инструментов разработчика в Chrome.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]