在我尝试为我的项目执行此操作时找到了您的帖子.我搞定了.对于将来需要它的任何人来说,jqGrid将无法与JSON和ASP.NET一起开箱即用.你需要对grid.base.js进行一些小的修改.在第829行附近,用以下内容替换json案例部分:
case "json":
gdata = JSON.stringify(gdata); //ASP.NET expects JSON as a string
$.ajax({ url: ts.p.url,
type: ts.p.mtype,
dataType: "json",
contentType: "application/json; charset=utf-8", //required by ASP.NET
data: gdata,
complete: function(JSON, st) { if (st == "success") { addJSONData(cleanUp(JSON.responseText), ts.grid.bDiv); if (loadComplete) { loadComplete(); } } },
error: function(xhr, st, err) { if (loadError) { loadError(xhr, st, err); } endReq(); },
beforeSend: function(xhr) { if (loadBeforeSend) { loadBeforeSend(xhr); } } });
if (ts.p.loadonce || ts.p.treeGrid) { ts.p.datatype = "local"; }
break;
Run Code Online (Sandbox Code Playgroud)
然后添加以下功能:
function cleanUp(responseText) {
var myObject = JSON.parse(responseText); //more secure than eval
return myObject.d; //ASP.NET special
}
Run Code Online (Sandbox Code Playgroud)
您还需要包含JSON解析器和字符串.除了使用ASP.NET之外,这个修改后的代码也更安全,因为eval语句已经消失.
编辑:我应该也注意到你可能需要对grid.celledit.js,grid.formedit.js,grid.inlinedit.js和grid.subgrid.js进行类似的编辑.