簡體   English   中英

jqGrid:如何使用導航器中的添加行在數據庫中插入數據?

[英]jqGrid: How to insert data in database using add row in navigator?

這是我的jQuery腳本

$("table#list").jqGrid({
url:'example.php',
datatype: 'json',
mtype: 'POST',
colNames:['ID', 'Position', 'Abrv', 'Department'],
colModel :[ 
{name:'id', index:'id', width:40, hidden: true, editrules:{edithidden:true}}, 
{name:'position', index:'position', width:300, editable: true, required: true},
{name:'abvr', index:'abvr', width:50, editable: true, required: true}, 
{name:'department', index:'department', editable: true, edittype: 'select', editoptions:{dataUrl: 'test2.php'}}
],
width: 600,
height: 250,
rownumbers: true,
pager: '#pager',
rowNum: 10,
rowList:[10,20],
sortname: 'id',
sortorder: 'ASC',
viewrecords: true,
gridview: true,
caption: 'Position',
loadError : function(xhr,st,err) {
$("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
},
editurl: 'insertDB.php'
}); 

insertDB.php

 if($_POST['oper'] == 'add'){
$position = $_POST['position'];
$department = $_POST['department'];

$query = "INSERT INTO test_position VALUES ('', '$position', '$department')";
$run = mysql_query($query);
}

提交表格時沒有任何反應。 我的數據庫同樣不會更新。

  1. 我在PHP中的發布變量不正確嗎?
  2. 有沒有一種方法來獲取insertDB.php返回的內容並將其顯示在jQuery中?

我忘了選擇一個數據庫。 我在使用FireBug之后發現了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM