invalid json it says!!
invalid json it says!!
Dear all,
I've been getting this error and I don't know what to do..
It says..
"Uncaught Error: DataTables warning: table id=grid - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"
Although json lint/formatter says my json is valid..
what to do now?
here is my json outcome..
{
"data": [{
"SMID": 1869576,
"FromNum": "611500000",
"ToNum": "611550000",
"MessageText": "some text, few words",
"SendDate": "\/Date(1546290000527)\/",
"Done": 0,
"UserID": 2754
}, {
"SMID": 1869577,
"FromNum": "66170497888",
"ToNum": "66171675858",
"MessageText": "Media: type: image/jpg - file name: img-20181230-wa0016.jpg",
"SendDate": "\/Date(1546290001670)\/",
"Done": 1,
"UserID": 5352
}, {
"SMID": 1869578,
"FromNum": "611508158855",
"ToNum": "611556659881",
"MessageText": "some text, few words",
"SendDate": "\/Date(1546290006817)\/",
"Done": 1,
"UserID": 2754
}, {
"SMID": 1869579,
"FromNum": "66170497888",
"ToNum": "6613798279",
"MessageText": "Media: type: image/jpg - file name: img-20181230-wa0016.jpg",
"SendDate": "\/Date(1546290008540)\/",
"Done": 1,
"UserID": 5352
}, {
"SMID": 1869580,
"FromNum": "611508158855",
"ToNum": "611565560601",
"MessageText": "some text, few words",
"SendDate": "\/Date(1546290014530)\/",
"Done": 0,
"UserID": 2754
}, {
"SMID": 1869581,
"FromNum": "66170497888",
"ToNum": "66176112593",
"MessageText": "Media: type: image/jpg - file name: img-20181230-wa0016.jpg",
"SendDate": "\/Date(1546290015593)\/",
"Done": 1,
"UserID": 5352
}, {
"SMID": 1869582,
"FromNum": "611508158855",
"ToNum": "611595583875",
"MessageText": "some text, few words",
"SendDate": "\/Date(1546290021540)\/",
"Done": 0,
"UserID": 2754
}, {
"SMID": 1869583,
"FromNum": "66170497888",
"ToNum": "66171027098",
"MessageText": "Failed media",
"SendDate": "\/Date(1546290023097)\/",
"Done": 0,
"UserID": 5352
}, {
"SMID": 1869584,
"FromNum": "611508158855",
"ToNum": "611544112626",
"MessageText": "some text, few words",
"SendDate": "\/Date(1546290028560)\/",
"Done": 0,
"UserID": 2754
}, {
"SMID": 1869585,
"FromNum": "66170497888",
"ToNum": "6613372159",
"MessageText": "Media: type: image/jpg - file name: img-20181230-wa0016.jpg",
"SendDate": "\/Date(1546290029770)\/",
"Done": 1,
"UserID": 5352
}],
"draw": null,
"recordsTotal": 2306848,
"recordsFiltered": 2306848
}
Answers
Not sure if this is causing the error but this part is not correct:
According to the server side processing docs the
drawparameter is expected to be an integer. Thedrawparameter is a sequence and your server script is expected to return the sequence number sent to it.Kevin
I double checked the response.. it is as below
And my Javascript is like this:
I suspect the problem is due to defining
serverSide: truebut not usingajaxwithin the Datatables init code. It also looks like you have some ajax config options (lines 46 and 47) in the Datatables init code which aren't doing anything. Please add use theajaxoption instead of the external ajax request with server side processing.You can use
ajax.datato pass the parameters to the server. The docs show some examples. When using theajaxoption make sure you don't use thesuccessfunction as noted in the docs.Kevin
Yep, as Kevin said, if you've enabled
serverSide, then DataTables needs to be in control of the Ajax requests. If you don't need server-side processing, just remove that option and you'll be good.C