目前我从服务器端文件获取数据并使用AJAX将结果传递给我的html。这样做是为了让我可以在不刷新页面的情况下获取新数据。
问题 Datatable没有对它进行处理,因为它无法将我的服务器端结果识别为数据。相反,它显示“0个条目中显示0到0”。当我尝试搜索它时出现空白
HTML
<table id='example1' class='table table-hover table-striped'>
<thead>
<tr>
<th>Stat</th>
<th>Name</th>
<th>Problem</th>
<th>Time</th>
</tr>
</thead>
<tbody id='tab'>
</tbody>
<tfoot>
<tr>
<th>Stat</th>
<th>Name</th>
<th>Problem</th>
<th>Time</th>
</tr>
</tfoot>
</table>
AJAX
function ajaxCall() {
$.ajax({
url: "anfi.php",
success: (function (result) {
$("#tab").html(result);
})
})
};
ajaxCall(); // To output when the page loads
setInterval(ajaxCall, (5 * 1000)); // x * 1000 to get it in seconds
$(function () {
$("#example1").DataTable();
});
PHP文件
echo"<tr>";
$notarray = DataDB::getInstance()->select_from_desc('ticket','ticket_id');
foreach($notarray as $row):
$first = DataDB::getInstance()->get_name_from_id('firstname','user','user_id',$row['user_id']);
$last = DataDB::getInstance()->get_name_from_id('lastname','user','user_id',$row['user_id']);
$title = DataDB::getInstance()->get_name_from_id('name','ticket_title','ticket_title_id',$row['ticket_title']);
$full = $first.' '.$last;
echo"<td class='mailbox-star'><a href='#'><i class='fa fa-circle text-blue'></i></a></td>
<td class='mailbox-name'><a href='ticket_details?ref=".$row['reference']."'>" . $full . "</a></td>
<td class='mailbox-subject'><p class='carshow' title='".$title."- ". $row['subject'] . "'><b>" . $title . "</b>-" . $row['subject'] . "</p></td>
<td class='mailbox-date'>" . $row['ticket_open_date'] . "</td>
</tr>";
endforeach;
echo"</tr>";