本文共 1784 字,大约阅读时间需要 5 分钟。
我有一些jqGrid的问题。
我添加了一个验证用户输入的方法。 如果部门存在,那么它将显示一条警告信息,“部门存在!”
这是我的jqGrid代码:
afterSubmit: function(response, postdata){
var res = $.parseJSON(response.responseText);
if (res === "1") {
return [false,"Department Already Exist"];
} else {
return [true,"Sucess"];
}
}
我的php添加方法:
if($oper == 'add') {
$deptid = $_POST['idms_department'];
$deptnm = $_POST['department'];
if(checkUser($deptnm) == "FALSE"){
return "1";
} else {
$ins = "INSERT INTO ms_department(department) VALUES('$deptnm')";
if(mysql_query($ins)){
"Success INSERT msDept";
} else {
die("Failed : " .mysql_error());
}
}
mysql_close();
} else .... (another operation)
消息本身未显示。 你如何正确使用afterSubmit方法? 谢谢
UPDATE
我已将方法更改为
crudMessage = function(response,postdata){
var res = response.responseText; // response text is returned from server.
if (res === "1") {
return [false,"Department Already Exist"];
} else {
return [true,"Sucess"];
}
}
然后从jqgrid主体中删除afterSubmit并将此行添加到jqgrid导航中:
jQuery("#departments").jqGrid('navGrid','#pager-departments',{edit:true,add:true,del:true}, {closeAfterEdit: true},{beforeShowForm: function(form) { $('#idms_department', form).hide(); },closeAfterAdd:true},{afterSubmit: crudMessage},{closeAfterSearch:true},{});
这是最新的PHP语法:
include 'configuration.php';
function checkDepartment($department){
$query = "SELECT department FROM ms_department WHERE department ='$department' LIMIT 1";
$result= mysql_query($query);
return mysql_num_rows($result);
}
if($oper == 'add') {
$deptid = $_POST['idms_department'];
$deptnm = $_POST['department'];
if(checkDepartment($deptnm) == 1){
echo '1';
} else {
$ins = "INSERT INTO ms_department(department) VALUES('$deptnm')";
if(mysql_query($ins)){
"Success INSERT msDept";
} else {
die("Failed : " . mysql_error());
}
}
mysql_close();
} else
if($oper == 'edit'){ ....
转载地址:http://tkyhp.baihongyu.com/