我正在使用codeigniter的项目。我试图使用数据表来查看由Ajax获取的数据。网络选项卡显示AJAX正确返回值,但该功能被标记为404,我得到这个错误datagables by ajax codeigniter问题
"DataTables warning: table id=data - Ajax error. For more information about this error, please see http://datatables.net/tn/7"
下面是在网络选项卡中的AJAX
我检查的响应和这是正确的。我已经打开了AJAX功能是这样的:domain.com/module/controller/merchantsTable,我得到了正确的数据
{ "merchantsdata":[{"id":"6","email":"[email protected]"},{"id":"7","email":"[email protected]"}]}
数据表代码[更新:增加了“加工”和“服务器端”]
<table id="data">
<thead>
<tr>
<th>id</th>
<th>email</th>
</tr>
</thead>
<tfoot>
<tr>
<th>id</th>
<th>email</th>
</tr>
</tfoot>
<tbody>
</tbody>
</table>
//base_url refers to https://www.domain.com/
$(function() {
$('#data').DataTable({
"processing": true,
"serverSide": true,
"ajax": "<?=base_url()?>merchants/admin_merchants/merchantsTable",
"columns": [
{ "merchantsdata": "id" },
{ "merchantsdata": "email"}
],
"order":[0 , 'desc'],
"lengthMenu": [[20, 50, -1], [20, 50, "All"]]
});
});
那么如何解决这个问题并使其工作?
很明显,反应实际上是不正确的。您的数据存在,但Datatables需要额外的参数才能工作。看看[这个SO回答](http://stackoverflow.com/questions/26387356/codeigniter-with-datatables-ajax-populate) – markpsmith
工作,而无需修改代码。我的错误是在名为'merchants'的根目录中有另一个文件夹,所以ajax没有从codeigniter路径路径中获取数据,而是从根目录中的文件夹获取数据。谢谢你的帮助 –