While trying to render a datatable with ajax sourced data, I get a
400 bad request
as ajax response.
The Json I get from the ajax call is as below which is happily validated by Jsonlint
{
"data": {
"title": "Seminar",
"pdate": "2016-02-05",
"duedate": "2016-03-04"
}
}
I am using the following javascript suggested by datatables for rendering ajax sourced data ;
$('#table1').DataTable({
ajax: {
url: '?r=site/test',
type: 'POST',
dataSrc: 'data'
},
columns: [
{ data: 'title' },
{ data: 'pdate' },
{ data: 'duedate' }
]
});
Here is the fiddle.
$b = [
'title'=> "Seminar",
'pdate'=> "2016-02-05",
'duedate' => "2016-03-04"
];
$a['data'][] = $b;
echo json_encode($a);
What's wrong ?