【发布时间】:2019-08-13 23:45:14
【问题描述】:
我有一个 HTML 表格存储在 table.html:
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
</table>
另一个页面包含一个名为“newtable”的 div,一个 ajax 脚本用于获取 table.html 的内容,将其插入名为“newtable”的 div 中并每 5 秒刷新一次。 该表使用引导数据表,这为我的表添加了一个搜索框和分页功能:
<body>
<div class="content table-responsive table-full-width newtable">
</div>
</body>
<script>
function table() {
$.ajax({
url: 'table.html',
type: 'get',
success: function(response){
$('.newtable').html(response);
}
});
}
table();
setInterval(table, 5000);
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</html>
当页面加载时,我的表格工作正常,但是在 ajax 刷新表格内容后,表格更新但是引导数据表功能(搜索栏和分页)消失,除非我自己刷新页面,否则不会重新出现.
我该如何解决这个问题?
【问题讨论】:
标签: javascript jquery html ajax datatables