Requested unknown parameter
Requested unknown parameter

Can you help me understand why this error comes up?
DataTables warning: table id=list - Requested unknown parameter 'date' for row 0, column 1.
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": '+'
},
{"data": "date"},
{"data": "name"},
{"data": "lastname"},
{"data": "email"},
],
The html is also correct. The json response does not give any error. I don't understand this.
This discussion has been closed.
Answers
Did you follow the troubleshooting steps at the link provided in the error?
https://datatables.net/manual/tech-notes/4
Sounds like the JSON data structure doesn't match what Datatables expects as described in the Ajax doc.
What is in the JSON response?
Kevin
I did not get an erro for json. Here is the json (with a length of 1 in the query)
{"draw":1,"recordsTotal":"20554","recordsFiltered":"20554","data":"[{\"date\":\"2020-02-18 18:46:34\",\"name\":\"Bueno Balboa\",\"lastname\":\"\",\"email\":\"xxxxxxxx@gemai.com\"}]"}
Looks like the correct structure except that the
data
object looks to be encapsulated into a JSON string twice:Note the
\
escaping the"
. My guess is your server script is encapsulating the data it collected, ie,[{\"date\":\"2020-02-18 18:46:34\",\"name\":\"Bueno Balboa\",\"lastname\":\"\",\"email\":\"xxxxxxxx@gemai.com\"}]
then doing another JSON encapsulation when returning the full response.Kevin
No this is not a problem. It's something in datatables script .I need to get why it is returning this error. As you see "date" is there, but for some reasons is telling that it is "unknown"
You are correct, the date is there. As I explained the problem is the
data
object has been JSON encapsulated twice so when Datatables parses thedata
object it is still a string causing the error. Let me dome for you.I took your data and
columns
definition and used it in this example:http://live.datatables.net/bilareco/1
Using
data
to provide the data to Datatables. The same alert message is displayed. You can click theEdit in JS Bin
button to see the code.Took the same code and use
JSON.parse()
on the data and now it works. Here is the updated example:http://live.datatables.net/bilareco/1
What are you using for your server script?
Kevin
I'm using php on the server and the same output works on another project. What do you mean with encapsulated twice ? I see only an array [], that's not "normally" a problem.
Sorry, I provided the wrong link for the second example:
http://live.datatables.net/yeyatato/1/edit
The
"
in front of the[
makes the data object a string not an array:When data is JSON encapsulated quotes (
"
) are used to wrap the text. If that data is JSON encapsulated a second time all the quotes in the original are escaped with backslashes.Is it one of the Datatables provided scripts or your own?
Kevin
Thank you! I didn't see it
Solved!!