>我有一个脚本来编码json字符串,以便以jquery数据表格式显示数据。
但是,该页面未显示任何内容!如果我使用 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.
如果我能做到这一点,那将是一个巨大的帮助!
我认为当您手动进行服务器处理时,您需要在响应中添加以下参数:
-
iTotalRecords
- 数据库中的记录总数 -
iTotalDisplayRecords
- 要显示的记录数
它们应与 JSON 响应中的aaData
参数处于同一"级别"。请参阅数据表指南,这些字段的用法应在此处解释。