I am trying to optimise the load of a page that has over 5000 rows of data being returned.
Instead of letting the ASP.Net Webforms code behind produce the HTML I am trying to achieve this using JQuery.
Please see my code below.
$.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);
}
}
which calls method that uses 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;
The example I am loosely following because I need to get the values from code behind rather than a text file can be found here https://datatables.net/reference/option/ajax
The error message that I am getting is
"{"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}"
I would be grateful if someone could help me understand where I am going wrong and what I need to do in order to resolve this.
Thanks