【发布时间】:2013-09-24 19:56:59
【问题描述】:
我正在尝试使用数据表和服务器端处理。这是我的看法:
<table id="datatables" class="display">
<thead>
<tr>
<th>Your Name</th>
<th>Date and Time</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$(document).ready( function () {
// DATATABLES CONFIGURATION
$('#datatables').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "results/loadReportsAction"
} );
});
</script>
在我的结果控制器中:
public function loadReportsAction() {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$row = array();
$output = array(
"iTotalRecords" => 34,
"iTotalDisplayRecords" => 34,
"aaData" => array()
);
$sessions = SessionQuery::create()->findByQuizId(3);
foreach($sessions as $session){
$row[] = "test";
$row[] = "test2";
$row[] = "test3";
$output['aaData'][] = $row;
$row = array();
}
echo json_encode( $output );
}
如您所见,我只是尝试加载“test”、“test2”等字符串。
我首先想让数据加载正确,然后创建过滤,排序,...。
当我加载这个时,我得到了这个错误:
DataTables 警告(表 id = 'datatables'):DataTables 警告:无法解析来自服务器的 JSON 数据。这是由 JSON 格式错误引起的。
这是我在回复中得到的:
或查看here。
他只显示现有的 HTML,而不是发送的 json。
【问题讨论】:
标签: php jquery zend-framework datatables server-side