使用JTable创建数据

时间:2015-02-06 16:29:02

标签: php jquery-jtable

美好的一天,我正在使用jtable创建数据,它会保存数据,但它会说“在与服务器通信时发生错误”。当我检查数据库时,它成功插入数据。 jtable中有2个字段,一个文本区域和一个下拉列表。这是我的jtable代码

<script>
$(function () { 
  $('#div').jtable({
            title: 'Division',
            paging: true, //Enable paging
            pageSize: 15, //Set page size (default: 10)
            sorting: true, //Enable sorting
            actions: {
                listAction: 'CRUD/Read.php',
                createAction: 'CRUD/Create.php',
                updateAction: 'CRUD/Edit.php',
                deleteAction: 'CRUD/Delete.php'
            },
            fields: {
                Id: {
                    key: true,
                    list: false
                },
                Description: {
                    title: 'Name',
                    width: '40%',
                    type: 'textarea'
                },
                IsActive: {
                    title: 'In Use',
                    width: '40%',
                    options: { 'N': 'No', 'Y': 'Yes' }
                }
            }
        });

    $('#div').jtable('load');
});
</script>

这里是php代码

<?php
//Insert record into database
$des = $_POST['ArticleDescription'];
$isActive = $_POST['IsActive'];
if($isActive == 'N'){
$query = mysql_query("INSERT INTO table VALUES( NULL,'" . $des . "','N')");
}
else
{
$updateAll = mysql_query("Update table Set IsActive = 'N'");    
$query = mysql_query("INSERT INTO table VALUES( NULL,'" . $des. "','Y')");  
}
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM table WHERE Id = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $result;
print json_encode($jTableResult);
?>

0 个答案:

没有答案