我正在尝试让 dataTables 插件处理网站的信息。我已经阅读了数据表的文档和各种 支持线程以及各种 StackOverflow 问题,但无济于事。根据上述文档,我拥有的代码应该可以正常工作......它没有。
Javascript:
$(document).ready( function(){
$('#results_table').dataTable( {
'bServerSide': true,
'sAjaxSource': 'results.php',
'fnServerParams': function ( aoData ) {
aoData.push( { 't': Math.random() });
}
});
});
HTML 代码:
<div id='results'>
<table id='results_table' >
<thead>
<tr>
<th>Num</th>
<th>Type</th>
<th>Access date</th>
<th>Access name</th>
</tr>
</thead>
<tbody>
</div>
PHP 片段(在检索/格式化 SQL 数据后:
$output = array('sEcho'=>1,'iTotalRecords'=>$count, 'iTotalDisplayRecords'=>$count, 'aaData'=> $results);
echo json_encode($output);
返回的数据(测试总数的一小部分):
{"sEcho":1,"iTotalRecords":3,"iTotalDisplayRecords":3,"aaData":[["1707052901-1A","D","Aug 17, 2012 1:54 PM","aqr"],["1707052901-1A","C","Aug 17, 2012 1:53 PM","aqr"],["2835602-4A","D","Aug 15, 2012 7:39 AM","aqr"]]}
现在,当我用数据表加载页面时,我收到了一个非常有用的答案——
未捕获的类型错误:无法读取未定义 jquery.dataTables.min.js:49 的属性“长度”
并且该表没有填充信息。
问题:我做错了什么;为什么我对数据表的服务器端处理的实现不起作用?如何解决此问题以正确显示?