我在Codeigniter中使用Ignited Datatables来显示数据库中的数据。它工作正常,数据正常显示。但是,当我在数据表中搜索特定数据时(使用数据表搜索框),它显示出如下错误:
DataTables警告:表id =表-Ajax错误。有关此错误的更多信息,请参见http://datatables.net/tn/7
控制器:
public function json(){
header('Content-Type: application/json');
echo $this->m_bahan->json();
}
型号:
function json() {
$this->datatables->select('*');
$this->datatables->from('t_bahan');
return $this->datatables->generate();
}
查看:
<table id="table" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th width="5%">No</th>
<th>Nama Bahan Dasar</th>
<th width="175px"></th>
</tr>
</thead>
</table>
Javascript:
table = $('#table').DataTable({
processing: true,//Feature control the processing indicator.
serverSide: true,//Feature control DataTables' server-side processing mode.
order: [[1,'desc']],//Initial order.
// Load data for the table's content from an Ajax source
ajax: {
url: "bahan/json",type: "POST"
},//Set column definition initialization properties.
columns: [
{
data: 'id_bahan',orderable: false,render: function (data,type,row,meta) {
return meta.row + meta.settings._iDisplayStart + 1;
}
},{data: 'nama_bahan'},{
classname: 'center',defaultContent: '<button class="btn btn-warning fa fa-edit" data-toggle="modal" data-target="#editModal"> Ubah</button> <emsp/> <button name="delete" class="btn btn-danger fa fa-trash"> Hapus</button>'
}
]
});
但是,当我直接从浏览器访问bahan/json
网址时,它会打印json结果。
这是怎么了?