問題描述
我已經創建了我的網格,并希望使用網格的默認行為來刪除一行.
I have created my grid and would like to use default behaviour of the grid to delete a row.
這是我的網格設置代碼:
This is my grid setup code:
$("#grid").jqGrid('navGrid', '#grid_pager',
{ add: true, addtitle: 'Add Customer',
edit: true, edittitle: 'Edit Customer',
del: true, deltitle: 'Delete Customer',
refresh: true, refreshtitle: 'Refresh data',
search: true, searchtitle: 'Advanced search filters',
addfunc: addReferent, editfunc: editReferent
},
{}, // default settings for edit
{}, // default settings for add
{ // define settings for Delete
mtype: "post",
reloadAfterSubmit: true,
url: wsBaseUrl + 'CustomerService.asmx/DeleteCustomer',
resize: false,
serializeDelData: function(postdata) {
return JSON.stringify({ customerID: postdata.id });
}
},
{ // define settings for search
closeOnEscape: true, multipleSearch: true, closeAfterSearch: true
},
{}
);
這是在服務器上定義的網絡服務方法
and this is the web service method defined on the server
[WebMethod]
public OperationResult Deletecustomer(string customerID)
{
}
但不幸的是,當我單擊刪除按鈕并在確認窗口上單擊確定時,我收到一條錯誤消息 404.如下圖所示
but unfortunately when I click the delete button and click ok on the confirm window I get an error saying 404. as in the following picture
我做錯了什么?
我已將以下代碼添加到我的 jqGrid 初始化中
I have added the following code to my jqGrid Initialization
// Set defaults value for jqGrid
$.jgrid.defaults = $.extend($.jgrid.defaults, {
mtype: 'post',
datatype: 'json',
jsonReader: {
root: "d.Rows",
page: "d.Page",
total: "d.Total",
records: "d.Records",
repeatitems: false,
userdata: "d.UserData",
id: "Id"
},
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
ajaxDelOptions: { contentType: 'application/json; charset=utf-8' },
serializeDelData: function (postData) {
return JSON.stringify(postData);
},
loadui: "block",
multiboxonly: true,
rowNum: 25,
rowList: [25, 50, 100],
altRows: true,
altclass: 'ui-priority-secondary',
autoencode: true,
autowidth: true,
rownumbers: true,
rownumWidth: 30,
gridview: true,
hoverrows: true,
viewrecords: true
});
但我仍然遇到同樣的錯誤...
but I still get the same error...
推薦答案
也許你應該只使用 JSON.stringify
(來自 json2.js) 在 serializeDelData
內.您沒有發布您需要刪除的網絡方法 DeleteCustomer
的原型,但您的問題可能可以通過以下代碼解決:
Probably you should just use JSON.stringify
(from json2.js) inside of serializeDelData
. You don't posted the prototype of your web method DeleteCustomer
which you need to delete, but probably your problem could be fixed with the following code:
serializeDelData: function(postdata) {
return JSON.stringify({customerID: postdata.id});
}
使用 ASMX 服務時的另一個常見問題.可能需要定義調用的 Web 方法的所有參數(參見 這里一個例子).
One more common problem in case of the usage of ASMX services. It can be need to define all parameters of the web method called (see here an example).
ajaxDelOptions: { contentType: "application/json" }
參數的用法也大多是必需的.
The usage of ajaxDelOptions: { contentType: "application/json" }
parameter is also required mostly.
使用 Fiddler 或 Firebug 來捕獲和分析 HTTP 流量.
It can be helpful to use Fiddler or Firebug to capture and analyse the HTTP traffic.
這篇關于jqGrid 刪除一行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!