我有一个包含2个数组的多个对象的json数据,我将以下代码放在一起,使我只能进行一次调用并将结果拆分为2个表。我现在面临的问题是我无法再刷新表格了。我已尝试不同的选项,但得到无法重新初始化DataTable这是有道理的,所以我想我现在卡住了。刷新数据表时出错 - 无法重新初始化DataTable
代码:
$(document).ready(function(){
setInterval (function(){
$.getJSON("ajax/json.txt", function (pcheckdata){
<!-- ------------------- Extract Only Alerts ---------------------- -->
$('#alert-table').dataTable({
"bJQueryUI": true,
"data": pcheckdata.alerts,
"columns": [
{ "mData": "host" },
{ "mData": "description" }
],
});
<!-- ------------------- Extract Only Errors ---------------------- -->
$('#error-table').dataTable({
"bJQueryUI": true,
"data": pcheckdata.errors,
"columns": [
{ data: 'host' },
{ data: 'description' }
],
});
});
}, 1000);
});
我的JSON结构
{
"alerts": [
{
"host": "server1",
"description": "Engine Alive"
},
{
"host": "ftpserver",
"description": "Low free disk space"
}
],
"errors": [
{
"host": "server3",
"description": "Can't connect to MySQL server"
},
{
"host": "server4",
"description": "SSQL timeout expired"
}
]
}
HTML位:
<table id="alert-table" class="display" cellspacing="0">
<thead class="t-headers">
<tr>
<th>HOST</th>
<th>DESCRIPTION</th>
</tr>
</thead>
</table>
<table id="error-table" class="display" cellspacing="0">
<thead class="t-headers">
<tr>
<th>HOST</th>
<th>ERROR DESCRIPTION</th>
</tr>
</thead>
</table>
我很想知道是否有刷新在2代表的方式同一时间,因为数据只会被提取一次,或者更好地使用纯粹的JQUERY,并忘记数据表,因为它eems让我头痛
你能告诉我有两个ID的HTML的一部分?我也使用dataTables。 – kefy 2014-09-03 11:18:21
我已经添加了表位。这只是基本的表结构 – Chelseawillrecover 2014-09-03 11:23:13