请问 : jqgrid4--inline模式,如何根据服务器返回值判定数据是否保存,如果服务器保存数据失败,如何在客户端显示给出服务器端传送过来的错误消息(用一个变量表示),并阻止客户端保存.需要改变jqgrid哪个事件的响应函数?
谢谢!
客户端代码如下: 目前可以传送数据到服务器端,服务器端返回{"message":"存在重复数据,增加数据失败!","new_id":-1,"success":false},但不知道客户端如何处理,客户端应该接受什么样的数据呢?
- JScript code
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Insert title here</title> <link href="/education2/jqGrid4.4/themes/redmond/jquery-ui-1.8.2.custom.css" rel="Stylesheet" /> <link href="/education2/jqGrid4.4/themes/ui.jqgrid.css" rel="Stylesheet" /> <script src="/education2/jqGrid4.4/js/jquery-1.7.2.js" type="text/javascript"></script> <script type="text/javascript" src="/education2/jqGrid4.4/js/jquery-ui-1.8.2.custom.min.js"></script> <script type="text/javascript" src="/education2/jqGrid4.4/js/i18n/grid.locale-cn.js"></script> <script src="/education2/jqGrid4.4/js/jquery.jqGrid.src.js" type="text/javascript"></script> <script type="text/javascript"> jQuery(document).ready(function() { jQuery("#gridTable").jqGrid({ url : '/education2/json/searchTeacher', mtype : "GET", datatype : "json", colNames : [ 'Id', '姓名', '职称', '院系', '教研室', '学历', '出生年月' ], colModel : [ { name : 'teacherId', index : 'teacherId', width : 55, hidden : true, hidedlg : true,//form中不出现 key : true }, { name : 'teacherName', index : 'teacherName', width : 90, editable : true }, { name : 'teacherTitle', index : 'teacherTitle', width : 100, editable : true, edittype : 'select', editoptions : { value : '讲师:讲师; 副教授:副教授; 教授:教授' } }, { name : 'teacherDepartment', index : 'teacherDepartment', width : 80, align : "right", edittype:'select', editoptions:{dataUrl : "/education2/json/departmentTeacher"}, editable : true }, { name : 'teacherSection', index : 'teacherSection', width : 80, align : "right", editable : true }, { name : 'teacherEducation', index : 'teacherEducation', width : 80, align : "right", editable : true }, { name : 'teacherBirthday', index : 'teacherBirthday', width : 150, sortable : false, editable : true } ], jsonReader : { root : "gridModel", records : "record", repeatitems : false }, prmNames : { search : "search", id : "id" /////////inline模式 id不能等于表字段名,否则增加记录出错 }, // jqGridInlineAfterSaveRow : function(rowid, resp, tmp, o) { // }, rowNum : 10, rowList : [ 10, 20, 30 ], // multiselect : true, // multiboxonly : true, pager : jQuery('#gridPager'), sortname : 'teacherId', viewrecords : true, sortorder : "desc", editurl : "/education2/json/editTeacher", caption : "教师" }); jQuery("#gridTable").jqGrid('navGrid', "#gridPager", { edit : false, add : false, del : false }, {}, {}, {},{ caption : "查找", Find : "开始查找", closeAfterSearch : true }); jQuery("#gridTable").jqGrid('inlineNav', "#gridPager"); }); </script> </head> <body> <table id="gridTable"></table> <div id="gridPager"></div> <br /> </body> </html>