Reload and Show Data (Server Side Processing)
Reload and Show Data (Server Side Processing)

Hello @all,
I'm a completly new to AJAX / datatables (coming from c++),
so sorry for my question.
I use server-side-processing to get data from a database.
The table is shown sucessfully, but I want to reload the data source each 10 seconds to
and show the updated values:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TestPage</title>
</head>
<body>
<table id="memListTable" class="display" style="width:100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Gender</th>
<th>Country</th>
<th>Created</th>
<th>Status</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Gender</th>
<th>Country</th>
<th>Created</th>
<th>Status</th>
</tr>
</tfoot>
</table>
</body>
</html>
<!-- DataTables CSS library -->
<link rel="stylesheet" type="text/css" href="datatables.min.css"/>
<!-- jQuery library -->
<script src="jquery/jquery-3.3.1.min.js"></script>
<!-- DataTables JS library -->
<script type="text/javascript" src="datatables.min.js"></script>
<script>
var table = $(document).ready(function(){
$('#memListTable').DataTable({
"processing": true,
"serverSide": true,
"responsive": true,
"keys": true,
"ajax": "getData.php",
"dom": "Bfrtip",
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5'
]
});
});
setInterval( function () {
table.ajax.reload();
}, 10000);
</script>
The timer-function works as expected, but the data is not actualized.
I also tried the draw()-function without success.
Can somebody help me?
Best regards
Moppi
This question has an accepted answers - jump to answer
Answers
I suspect you are seeing an error in your browser's console regarding the line
table.ajax.reload();
. You need to move thevar table =
in line 46 to line 47 to assign the Datatables API to the variabletable
.Kevin
Hi Kevin,
thanks for answer;
I have to say I'm sorry, I activated the console and solved the problem in the following way:
Thank you for fast support.
Best regards
Moppi