Jquery DataTable在单击按钮尝试加载数据时在警报框中显示错误
我使用的是最新的1.10.15版本。单击id为Jquery DataTable在单击按钮尝试加载数据时在警报框中显示错误,jquery,ajax,datatables,Jquery,Ajax,Datatables,我使用的是最新的1.10.15版本。单击id为btn\u search的按钮时,表格将充满数据 HTML: 我在警报框中发现此错误: DataTables warning: table id=example - Requested unknown parameter 'id_trace' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
btn\u search
的按钮时,表格将充满数据
HTML:我在警报框中发现此错误:
DataTables warning: table id=example - Requested unknown
parameter 'id_trace' for row 0, column 0. For more information
about this error, please see http://datatables.net/tn/4
在firebug中,我可以看到如下ajax响应:
[{"id_trace":"462036","mac":"e8:03:9a:0c:d0:06","dest_ip":"206.54.163.50",
"dest_port":"443","src_ip" :"10.10.10.37","src_port":"54707"},{"id_trace":"462037",
"mac":"e8:03:9a:0c:d0:06","dest_ip":"104.193
.36.37","dest_port":"80","src_ip":"10.10.10.37","src_port":"53544 {"id_trace":"462038",
"mac":"6c:b0:ce:85:50:01","dest_ip":"52.42.48.105",
"dest_port":"80","src_ip":"10.10.10.38","src_port":"46944"},{"id_trace" .......
那么,单击按钮时如何实现数据加载?您的JSON中有一些严重错误。更正它们,您的代码就会工作。清理后,
Table.rows.add(result).draw()立即工作。您看到了哪些错误?json响应未在OP.中完全显示代码>添加在后面。1)json是通过PHP代码“echo json_encode($query_result);”生成的。那我在这里该怎么办?2) 如果我在ajax调用中添加dataType:json
,则不会显示错误警报,但表中也没有加载数据。我真的不知道您缺少什么,但是如果您传递一个包含您描述的项目的有效json,那么您的客户端代码实际上可以工作->如果您也可以包含ajax调用,那将非常有用。
$sql='SELECT `id_trace`,`mac`, `dest_ip`, `dest_port`, `src_ip`, `src_port` FROM `trace`';
$sql='SELECT * FROM `trace`';
$query = $this->db->query($sql);
$query_result=$query->result();// this codeigniter code
merely holds an associative array
echo json_encode($query_result);
DataTables warning: table id=example - Requested unknown
parameter 'id_trace' for row 0, column 0. For more information
about this error, please see http://datatables.net/tn/4
[{"id_trace":"462036","mac":"e8:03:9a:0c:d0:06","dest_ip":"206.54.163.50",
"dest_port":"443","src_ip" :"10.10.10.37","src_port":"54707"},{"id_trace":"462037",
"mac":"e8:03:9a:0c:d0:06","dest_ip":"104.193
.36.37","dest_port":"80","src_ip":"10.10.10.37","src_port":"53544 {"id_trace":"462038",
"mac":"6c:b0:ce:85:50:01","dest_ip":"52.42.48.105",
"dest_port":"80","src_ip":"10.10.10.38","src_port":"46944"},{"id_trace" .......