【发布时间】:2016-10-09 05:29:50
【问题描述】:
我已经阅读了一些关于 SO 的答案以及一些教程和关于 ajax/dataTables 的文档。我的 dataTable 仍然不会填充 JSON 数据。
HTML:
<table id="table" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Status</th>
<th>Student Name</th>
<th>Exam Name</th>
<th>School</th>
<th colspan="2">Action</th>
</tr>
</thead>
<tfoot>
<th>Status</th>
<th>Student Name</th>
<th>Exam Name</th>
<th>School</th>
<th colspan="2">Action</th>
</tfoot>
</table>
Javascript:
<script type="text/javascript">
$(document).ready(function() {
// Datatables
$('#table').DataTable({
"url": "<?php echo site_url('exams/ajax_list'); ?>",
});
});
</script>
考试控制器中的 ajax_list PHP 函数:
public function ajax_list() {
$list = $this->exam_model->get_datatables();
$data = array();
foreach ($list as $exam) {
$row = array();
$row[] = $exam->exam_status;
$row[] = $exam->first_name . " " . $exam->last_name;
$row[] = $exam->exam_name;
$row[] = $exam->exam_school;
$data[] = $row;
}
echo json_encode($data);
}
从导航到该方法时可以看到,json_encode 正确输出,但 dataTable 仍然为空。
我错过了什么吗?
【问题讨论】:
-
你是否仔细检查了ajax_list的路径?
标签: php jquery ajax codeigniter datatable