I am trying to follow an example of adding data to a datatables.net datatable using a JSON response based on this example https://www.datatables.net/examples/ajax/objects.html.
I am using an AJAX call to get a JSON response from a database.
I am getting the data and then using NewtonSoft JSON.Net to convert a datatable into a JSON array as per the code below
string jsonResult = null;
jsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
jsonResult = jsonResult.Replace("[{", "{\"data\" :[{").Replace("}]", "}]}");
return jsonResult;
This is being successfully called from an AJAX call in a separate javascript file as per the next code snippet
$.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);
populateTable(data.d, tableId);
},
error: function (data) {
console.log(data);
}
}
Which then passes the returned values to a function that should format enter the data into the datatable accordingly as per the next set of code
function populateTable(json, tableId) {
try {
var table = $('#table_' + tableId).DataTable({
"processing": true,
"serverSide": true,
"ajax": json,
"columns:": [
{ "data": "CaseHandlerStaffNumber" },
{ "data": "RiskProfileText" },
{ "data": "AssignedCheckerStaffNumber" },
{ "data": "FeedbackUserStaffNumber" },
{ "data": "ComplaintRef" },
{ "data": "ChildComplaintRef" },
{ "data": "CaseTypeText" },
{ "data": "CheckGrade" }
]
});
} catch (e) {
}
}
The problem that I am getting is similar to this question here jquery datatables Ajax-Error / http://datatables.net/tn/7 however, I have tried this users solution and have the same issue.
I have followed all the recommended steps as detailed here https://www.datatables.net/manual/tech-notes/7 but do not see anything wrong with the responses that come back that relate to this.
I would be grateful if anyone could help me with this as I cannot see a way around the issue at the moment
thanks
Simon