Error using AJAX, but with correctly formed JSON response - Help
Error using AJAX, but with correctly formed JSON response - Help
Hi,
I am trying to optimise a page and am using an AJAX call to get the response using JSON. The code I am using is as 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);
try {
var table = $('#table_' + tableId).DataTable({
"ajax": data.d,
"columns:": [
{ "data": "CaseHandlerStaffNumber" },
{ "data": "RiskProfileText" },
{ "data": "AssignedCheckerStaffNumber" },
{ "data": "FeedbackUserStaffNumber" },
{ "data": "ComplaintRef" },
{ "data": "ChildComplaintRef" },
{ "data": "CaseTypeText" },
{ "data": "CheckGrade" }
]
});
} catch (e) {
}
},
error: function (data) {
console.log(data);
}
}
);
The error message I get is "DataTables warning: tavle id=table_14 - Ajax error. For more info..... please see http://...../tn/7"
When looking at this is directed me to tn1, which informed me to check my JSON.
After going to JSONLint it confirmed that the JSON is valid, but I cannot get passed this error. I would be grateful if anyone could help me get passed this issue.
thanks
Simon
This question has an accepted answers - jump to answer
Answers
ajax
is the DataTables configuration object. But you already have the data - so usedata
to pass the data in!Out of interest, have you seen the above in the documentation or on a blog somewhere? There have been a number of posts with this same issue recently.
Allan
I didn't see any others if I am honest, but that has resolved that issue I believe but now I have another that I need to look into.
thank you
Good to hear that helped. I need to see if I can improve the error handling in DataTables to catch this kind of thing :-)
Allan