我正在使用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路徑路徑中獲取數據,而是從根目錄中的文件夾獲取數據。謝謝你的幫助 –