我正在尝试优化返回超过5000行数据的页面的负载。
而不是让ASP.Net Webforms代码生成HTML我试图使用JQuery实现这一点。
请参阅下面的代码。
$.ajax({
type: "POST",
url: "TeamChecks.aspx/GetDataTables",
data: JSON.stringify(params),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//console.log(data.d);
var table = $('#hidJson_tbl_2').DataTable({
"ajax": data.d,
"columns:": [
{ "data": "CaseHandlerStaffNumber" },
{ "data": "RiskProfileText" },
{ "data": "AssignedCheckerStaffNumber" },
{ "data": "FeedbackUserStaffNumber" },
{ "data": "ComplaintRef" },
{ "data": "ChildComplaintRef" },
{ "data": "CaseTypeText" },
{ "data": "CheckGrade" }
]
});
},
error: function (data) {
console.log(data);
}
}
调用使用NewtonSoft Json.Net的方法
TeamChecks tc = new TeamChecks();
DataTable dtMc = default(DataTable);
dtMc = tc.Get_DatatableFor_GridView(userId, CheckStatusId);
string jsonResult = null;
jsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(dtMc);
jsonResult = jsonResult.Replace("[{", "{data:[{").Replace("}]", "}]}");
return jsonResult;
我正在松散地遵循这个例子,因为我需要从代码后面而不是文本文件中获取值https://datatables.net/reference/option/ajax
我收到的错误消息是
" {" Message":"使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了maxJsonLength属性上设置的值。"," StackTrace":"在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj,StringBuilder输出,SerializationFormat serializationFormat)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj,SerializationFormat serializationFormat)\ r \ n at at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context,WebServiceMethodData methodData,IDictionary`2 rawParams)\ r \ n在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context,WebServiceMethodData methodData)" " ExceptionType":" System.InvalidOperationException"}"
如果有人能帮助我了解我哪里出错了以及我需要做些什么来解决这个问题,我将不胜感激。
由于