jqgrid添加行并将数据发送到webservice以进行插入

我已经能够使用jQuery / Ajax从Web服务中将数据从我的数据库中提取到jQGrid中。 现在我想将添加/编辑的数据发送回webservice。 我通过使用PHP和editurl:命令看到了一些例子。 这也适用于Web服务(就像我最初下载数据一样)?

我已多次查看这些例子了。 我甚至发现了另一个类似于我所问的问题 ,但是我找不到任何关于如何做我需要的实例。 有存在吗?

:更新:

jQuery(document).ready(function () { jQuery("#list").jqGrid({ datatype: processrequest, mtype: 'POST', jsonReader: { root: "ListExercise", //arry containing actual data page: "Page", //current page total: "Total", //total pages for the query records: "Records", //total number of records repeatitems: false, id: "ID" //index of the column with the PK in it }, colNames: ['Id', 'Exercise'], colModel: [ { name: 'exercise_id', index: 'exercise_id',editable:false }, { name: 'exercise_value', index: 'exercise_value',editable:true } ], caption: 'MyFitnessApplication', pager: '#pager', rowNum: 10, rowList: [10, 20, 30], sortorder: "desc", viewrecords: true, height: '250px', loadonce: true, editurl: "../webService/exercise_ws.asmx/insertRecord" }).navGrid('#pager', { edit: true, add: true, del: false }); }); 

如您所见,我添加了editurl标记。 这似乎打电话给我的网络服务。 现在我想念如何将实际参数传递给webservice。 我错过了什么,感谢帮助!

首先,您可以更改用于添加/编辑的一些默认选项:

 jQuery.extend(jQuery.jgrid.edit, { ajaxEditOptions: { contentType: "application/json" }, recreateForm: true, serializeEditData: function (postData) { if (postData.exercise_value === undefined) { postData.exercise_value = null; } return JSON.stringify(postData); } }); 

(其中JSON.stringify是http://www.json.org/js.html中定义的函数)。 然后,将发送到服务器的数据将进行JSON编码。 几乎相同的设置可用于删除

 jQuery.extend(jQuery.jgrid.del, { ajaxDelOptions: { contentType: "application/json" }, serializeDelData: function (postData) { if (postData.exercise_value === undefined) { postData.exercise_value = null; } return JSON.stringify(postData); } }); 

现在您可以像下面一样定义insertRecord

 [WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)] public int ModifyData (string exercise_value, string oper, string id) { if (String.Compare (id, "_empty", StringComparison.Ordinal) == 0 || String.Compare (oper, "add", StringComparison.Ordinal) == 0) { // TODO: add new item with the exercise_value and return new id // as the method result } else if (String.Compare (oper, "edit", StringComparison.Ordinal) == 0) { // TODO: modify the data identified by the id } else if (String.Compare (oper, "del", StringComparison.Ordinal) == 0) { // TODO: delete the data identified by the id } } 

你没有写过哪个类型有exercise_id :整数或字符串。 如果使用字符串ID,则应稍微更改上面的代码。