我正在尝试让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 的属性"length"
并且该表不填充信息。
问题:我做错了什么;为什么我对dataTables的服务器端处理的实现不起作用??如何修复此问题以正确显示?
aoData.push( { 't': Math.random() });
应该这样使用:
aoData.push( { 'name': 't', 'value':Math.random() });
不确定这是否是问题所在,但这解决了我在使用数据表
时的一些问题