Reputation: 83
I use DataBase from https://www.datatables.net/
My problem is, I want to include or load the table content every x seconds. My scripts working without problems but datatables can't register the input if I load via js. A PHP include works without problems and datatables recognize the table content like a charme.
This is my JS "script":
$(document).ready(function() {
database();
setInterval(database, 10000);
});
function database() {
$("#database").load("getdb.php");
}
And this a part of my html/php code:
</tfoot>
<tbody id="database"></tbody>
</table>
Working part is:
</tfoot>
<tbody><?include("getdb.php");?></tbody>
</table>
Upvotes: 0
Views: 62
Reputation: 943651
You're changing the DOM, but you've already run the datatables script, so it isn't expecting the DOM to change and it doesn't read the new data from it.
Use the ajax.reload()
method instead.
In an environment where the data shown in the table can be updated at the server-side, it is often useful to be able to reload the table, showing the latest data. This method provides exactly that ability, making an Ajax request to the already defined URL
You will need to provide an ajax data source as well as (or instead of) the HTML generating PHP you have now.
Upvotes: 1