我正在使用JqGrid和我的WebForms网站设置来从[WebMethod()]获取数据。这是有效的,但现在我需要编辑帖子将内容发送回“Application / json”,但我没有运气。看着Fiddler,我看到帖子回到了“Application / x-www-form-urlencoded” - 我以为我找到并设置了所有正确的选项,但它仍然是不行的。
这是网格设置:
$.extend($.jgrid.edit, {
ajaxEditOptions: { contentType: "application/json; charset=utf-8" },
});
jQuery("#<%=jqGridName%>").jqGrid({
editurl: "/web/juicepress-misc-settings.aspx/saveJpUserException",
ajaxGridOptions: { contentType: "application/json; charset=utf-8", dataType: "json" },
ajaxEditOptions: { contentType: "application/json; charset=utf-8", dataType: "json" },
prmNames: {
search: "isSearch",
nd: null,
rows: "numRows",
page: "page",
sort: "sortField",
order: "sortOrder"
},
// Default values for search to make sure that the ajax call doesn't fail
postData: { searchString: '', searchField: '', searchOper: '' },
datatype: function(postdata) {
$.ajax({
url: '/Web/juicepress-misc-settings.aspx/getJpUserExceptions',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(postdata),
dataType: "json",
success: function(data, st) {
if (st == "success") {
var grid = $("#<%=jqGridName%>")[0];
var gridData = data.d;
grid.addJSONData(gridData);
}
},
error: function() {
alert("Error with AJAX callback");
}
});
},
height: <%=height %>,
width: <%=width %>,
jsonReader: {
id: "<%= keyDataField %>", //index of the column with the PK in it
repeatitems: false
},
colNames: [ <%= getColumnHeaders() %> ],
colModel: [ <%= getColumns() %> ],
multiselect: false,
gridview: true,
ignoreCase: true,
caption: "<%= gridTitle %>",
gridComplete: function(){
var ids = jQuery("#<%=jqGridName%>").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++){
var cl = ids[i];
be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=\"jQuery('#<%=jqGridName%>').editRow('"+cl+"');\" />";
se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=\"jQuery('#<%=jqGridName%>').saveRow('"+cl+"');\" />";
jQuery("#<%=jqGridName%>").jqGrid('setRowData',cl,{act:be+se});
}
}
});
我的服务是页面中的[WebMethod]装饰方法:
[WebMethod()]
public static void saveJpUserException(string name, string description, string oper, int id) {
...
}
答案 0 :(得分:0)
显然在线编辑不使用“ajaxEditOptions”,而是使用“ajaxRowOptions”(去图)......
所以解决这个问题:
ajaxRowOptions: { contentType: "application/json; charset=utf-8", dataType: "json" }