Luny Luny - 1 year ago 305
JSON Question

datatables refresh not working but recieve correct json

I have an error in my code and can’t figure out, what i did wrong.
The datatable gets filled correctly and on ajax.refresh the table gets valid json-data, but the table does not reload.


<table id="monatsabschluss" class="listing">
<thead class="header">
<th>Status<input type="checkbox" id ="express" ></th>


var adat = '20160606';
var kid = 7;
var table = $('#monatsabschluss').DataTable( {
"paging": false,
"info": false,
"filter": false,
"ordering": false,
"processing": true,
"serverSide": true,
"ajax": {
"url": "/management/bavabrech/fetchjobs",
"data": function ( d ) {
d.kid = kid;
d.adat = adat;
"dataSrc": "data",
"columns": [
{ "data": "description" },
{ "data": "status", className: 'statusCol' },
setInterval( function () {
table.ajax.reload( null, false );
}, 5000 );


[{"description":"Erstellen Rentendaten",
{"description":"Pr\u00fcfliste erstellen",

HTML-Output from the initial Datatable-loading

<table class="listing dataTable no-footer" id="monatsabschluss"
role="grid" style="width: 800px;">
<thead class="header">
<tr role="row">
<th class="sorting_disabled" rowspan="1" colspan="1"
style="width: 469px;">Aufgabe</th>
<th class="sorting_disabled statusCol" rowspan="1" colspan="1"
style="width: 269px;">Status<input type="checkbox" id="express">
<tbody class="">
<tr role="row" class="maStatusRunning">
<td>Erstellen Rentendaten</td>
<td class=" statusCol">Wird ausgeführt</td>
<tr role="row" class="maStatusComplete">
<td>Prüfliste erstellen</td>
<td class=" statusCol">Erledigt</td>
<tr role="row" class="odd">
<td class=" statusCol"></td>

I am using Datatable 1.10.7, i do not get any error messages.

Answer Source

Ok, I have installed all your code and dug deeper into the problem. Your issue is with your serverSide property. When that is on true, the client expects you to mirror the draw property send to the server so he know that the response he got is for the request he sent (see I also saw that you are using deprecated property names in your response (aaData etc....). You have to change those, so he recognizes your draw property.

That is how the response looks on my side and how it works in my example with your code

header('Content-type: application/json');
    "draw": <?= (int)$_GET['draw'] ?>,
        {"description":"Erstellen Rentendaten", "status":3,"id":"1"},
        {"description":"Pr\u00fcfliste erstellen", "status":4,"id":"2"},

I have added mirroring the draw property (you can see that in the request url) and renamed aaData to data, iTotalRecords to recordsTotal, iTotalDisplayRecords to recordsFiltered and removed iEcho

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download