ByVal datax As ObjectI'm嘗試使用ASP.NET和webmethod檢索數據併爲jqgrid保存數據。 我可以從webmethod檢索數據,但沒有運氣來做保存。 服務器端似乎從來沒有得到我的發佈數據。有人請幫忙嗎?jqgrid webmethod:未能保存行
電網代碼:
$('#list99').jqGrid({
datatype: function(postdata) {
$.ajax({
url: 'dbtest.aspx/getdata',
editurl: 'dbtest.aspx/updatedb',
type: 'POST',
data: '{}',
dataType: "json",
contentType: "application/json; charset=utf-8",
error: function(data, textStatus) {
alert('Error loading json');
},
success: function(data, st) {
if (st == 'success') {
var grid = $("#list99");
var gridData = JSON.parse(data.d);
grid.clearGridData();
for (var i = 0; i < gridData.length; i++) {
grid.addRowData(i + 1, gridData[i]);
}
}
$("#list99").jqGrid('navGrid', '#pager99', { add: true, edit: true, del: true });
}
});
},
type: 'POST',
editurl: 'dbtest.aspx/updatedb',
colNames: ['customerid', 'customername'],
colModel: [
{ name: 'customerid', index: 'customerid', width: 80, align: 'left', editable: true, edittype: 'text' },
{ name: 'customername', index: 'customername', width: 120, align: 'left', editable: true, edittype: 'text'}],
pager: $('#pager99'),
rowNum: 5,
rowList: [10],
sortname: 'customerid',
sortorder: 'desc',
viewrecords: true,
//width: 300
autowidth: true
});
服務器端代碼:
Public Class customer
Public customerid As String
Public customername As String
End Class
<System.Web.Services.WebMethod()> _
Public Shared Function getdata() As String
Dim c1 As New customer
Dim c2 As New customer
c1.customerid = "1"
c1.customername = "pete"
c2.customerid = "2"
c2.customername = "joah"
Dim lstcustomer As New List(Of customer)
lstcustomer.Add(c1)
lstcustomer.Add(c2)
Dim jsonserial As New JavaScriptSerializer
Dim result As String
result = jsonserial.Serialize(lstcustomer)
Return result
End Function
<System.Web.Services.WebMethod()> _
Public Shared Function updatedb(ByVal datax As Object) As String
//attempt to do save
End Function
功能updatedb的後我添加/編輯後點擊 「透過」 從來沒有被調用/刪除。
之後我檢查與螢火蟲,我得到了錯誤信息:
"Invalid web service call, missing value for parameter: 'data'."
我也嘗試添加以下內容:
jQuery.extend(jQuery.jgrid.edit, {
ajaxEditOptions: { contentType: "application/json" },
recreateForm: true,
serializeEditData: function(data) {
//alert('in2');
//alert(postData.customerid);
//alert(JSON.stringify(postData));
if (data.customerid == undefined) { data.customerid = null; }
var postData = { 'data': data };
//alert(postData.customerid);
return JSON.stringify(postData);
}
});
它仍然沒有工作=(
你看到AJAX呼叫出去了嗎?它是否包含發佈數據? – Mark
對不起,我是jquery的新手,我如何檢查AJAX調用是否結束? – user2045340
是的,我已經檢查了螢火蟲和AJAX電話出去,但我得到了這個錯誤信息: – user2045340