I have gone through several answers on SO as well as a few tutorials and the documentation on ajax/dataTables. My dataTable will still not populate with JSON data.
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 function in Exams controller:
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);
}
From what I can see when navigating to the method, the json_encode outputs correctly, but the dataTable is still empty.
Am I missing anything?