我有一个脚本来编码一个 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.
如果我能做到这一点,那将是一个巨大的帮助!