我似乎无法在jTable
中使用这些操作。我正在尝试删除记录,但它一直说An error occured while communicating to the server.
当我通过$_GET
发送ID时,它可以正常工作,所以它似乎没有正确发送POST
数据。有人对这个有经验么?非常感谢!
这是表脚本:
$('#PersonTableContainer').jtable({
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'Name ASC',
create: true,
title: 'Manage Students',
actions: {
listAction: 'listStudentsXHR.php?action=list',
createAction: 'createStudentsXHR.php?action=create',
updateAction: '',
deleteAction: 'deleteStudentsXHR.php?action=delete'
},
fields: {
userID: {
create: false,
title: 'ID',
key: true,
width: '3%'
},
username: {
title: 'Username',
width: '10%'
},
password: {
title: 'Password',
list: false,
type: 'password'
},
password_confirm:{
title: 'Confirm Password',
list: false,
type: 'password'
},
firstName: {
title: 'First Name',
width: '10%'
},
lastName: {
title: 'Last Name',
width: '10%'
},
points: {
create: false,
title: 'Points',
width: '10%'
},
level: {
create: false,
title: 'Level',
width: '5%'
},
status: {
create: false,
title: 'Status',
width: '10%'
},
curriculum: {
create: false,
title: 'Curriculum',
width: '10%'
},
numberCell: {
title: 'Cell Number',
width: '10%'
},
email: {
title: 'Email',
width: '10%'
},
},
});
$('#PersonTableContainer').jtable('load');
以下是发送给删除操作的PHP文件:
try {
require_once("includes/functions.php");
require_once("includes/session.php");
confirm_logged_in();
require_once("includes/db_connection.php");
if($_GET["action"] == "delete") {
$user_id = mysqli_real_escape_string($connection, $_POST['userID']);
//DELETE record from database
$query = "DELETE FROM user WHERE userID = {$user_id})";
$result = mysqli_query($connection, $query) or die('ERROR: '.mysqli_error());
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
} catch(Exception $ex) {
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}
答案 0 :(得分:2)
updateAction: ''
请提及要运行的代码的URL。将其留空导致此问题
答案 1 :(得分:0)
您必须使用$_REQUEST
或$_POST
获取通过post
方法发送的值,您在PHP代码中使用$_GET
,我更改了您的{{ 1}}代码,试试这个
php
答案 2 :(得分:0)
使用$_GET
而不是$_POST
发送默认的Jtable操作。这可能是您收到错误的原因。