DataTables warning: table id=example - Invalid JSON response. For more information about this error
DataTables warning: table id=example - Invalid JSON response. For more information about this error
hathim
Posts: 2Questions: 1Answers: 0
Hi, i am using datatables with struts 1.x with serverside processing. so i am sending the ajax request to the action servlet and processing it. I am trying to send some junk details from the server to the datatable. I am getting invalid json response. Please help me in that since I am stuck in this for more time .
Javascript code :
$(document).ready(function() {
$("#example").dataTable( {
"dom": '<"top"fl>rt<"bottom"ip><"clear">',
"processing": true,
"serverSide": true,
"ordering": false,
'bJQueryUI': true,
"sAjaxSource": "customerPaging.do",
"sServerMethod": "POST",
columns: [
{ "mData": "customer_number" },
{ "mData": "first_name" },
{ "mData": "last_name" },
{ "mData": "no_of_purchase" }
]
} );
Json response :
{ "draw" :1,"recordsTotal": 12,"recordsFiltered": 12,"mData": [["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"],["customer_number":"2017/0/0/0/1","first_name":"namelp","last_name":"nameas","no_of_purchase":"15"]]}
This discussion has been closed.
Answers
The json format is a valid one
Hi @hathim ,
By default, DataTables expects the data for the table to be within a
data
object in the Ajax response. For you, it's not, it's inmData
, so you'll need to specify that withajax.dataSrc
,Cheers,
Colin
Also the JSON format is not valid. You can test it using jsonlint. You have an array of objects but they are enclosed in square brackets
[]
instead of braces{}
.Instead of this:
It should look like this:
Kevin