我有一个脚本来编码json字符串,以便以jquery datatable格式显示数据。
但是,该页面没有显示任何内容!如果我使用jquery .post进行简单响应,则显示数据,但表失去其功能。
这是我到目前为止所做的事情
JSON编码脚本
$user = new Users();
$rcs_user = $user->get_all_users();
$response = '';
$arrResp = array();
$arrItems = array();
foreach ($rcs_user as $info)
{
$arrItems = array(utf8_encode($info->nome),$info->email,$info->permissao,$info->activo,'<span class="tip" >
<a title="Edit" ><img src="images/icon/icon_edit.png" ></a>
</span>
<span class="tip" >
<a id="1" class="Delete" name="Band ring" title="Delete" >
<img src="images/icon/icon_delete.png" >
</a></span>');
array_push($arrResp, $arrItems);
}
$array = array("aaData"=>$arrResp);
echo json_encode($array);
脚本输出的JSON字符串(使用JSONLint验证)
{
"aaData": [
[
"admin",
"a@a.pt",
"1",
"1",
"\r\n </a>\r\n </span> \r\n \r\n \r\n \r\n </a></span>"
],
[
"admin2",
"a@a.pt",
"1",
"1",
"\r\n </a>\r\n </span> \r\n \r\n \r\n \r\n </a></span>"
],
[
"António",
"a@a.com",
"10",
"0",
"\r\n </a>\r\n </span> \r\n \r\n \r\n \r\n </a></span>"
],
[
"João Dias",
"a@a.com",
"10",
"0",
"\r\n </a>\r\n </span> \r\n \r\n \r\n \r\n </a></span>"
],
[
"Zé Manel",
"zemanel@ze.com",
"10",
"1",
"\r\n </a>\r\n </span> \r\n \r\n \r\n \r\n </a></span>"
]
]
}
最后是jQuery
$(document).ready(function() {
$('#data_table3').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": 'modules/user/showusers.php'
} );
} );
每次重新加载页面时,都会收到此警告消息
Datatables Warining (tableid = data_table3): Cannot reinitialize table data. To retrieve the Data Objects for this table pass no arguments or see the docs for bRetrieve or bDestroy.
如果我开始工作,那将是一个巨大的帮助!
答案 0 :(得分:0)
我认为当您手动进行服务器处理时,需要在响应中添加以下参数:
iTotalRecords
- 数据库中的总记录iTotalDisplayRecords
- 要显示的记录数它们应与JSON响应中的aaData
参数处于同一“级别”。请参阅DataTables指南,那里应该解释这些字段的用法。