Can't read JSON without header
Can't read JSON without header
trusta77
Posts: 4Questions: 2Answers: 0
So I'm trying to do a row detail, using data from JSON following this Row Details
In that example, the jason have a header (I don't know what to call it, I'm relatively new to JSON and AJAX) like this :
{
"draw": 1,
"recordsTotal": 57,
"recordsFiltered": 57,
"data": [
While my JSON from json_encode array doesn't have this, it goes directly to data like this:
[{
"DT_RowId": "row_5",
"first_name": "Airi",
"last_name": "Satou",
"position": "Accountant",
"office": "Tokyo",
"start_date": "28th Nov 08",
"salary": "$162,700"
}]
Is there any way to parse the data without using the header or to set the header to my JSON?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
That header is only needed when
serverSide
is enabled - if it's not, or if it's set tofalse
then the header isn't required, only the second data that you pasted. What do you have in your initialisation?Colin
Previously my
serverSide
is true, but even after set it to false it's still show errorThis is my istallation look like:
Change:
to be
The data is at the top level of the returned object - the default would be 'data',
Colin
Oh, it's working nicely.
In my previous attempt, I use javascript to parse my ajax and then using
row.add()
to add data to the table in a loop, this one could actually save lots of time. Thankyou very muuch.