从DataTables中第0行的数据源请求未知参数"1"

Liv*_*eEn 5 php codeigniter-2 jquery-datatables

当我尝试从我的数据库中检索数据到表时,我收到此错误:

DataTables warning (table id = 'student_table'): Requested unknown 
parameter '1' from the data source for row 0
Run Code Online (Sandbox Code Playgroud)

下面是我使用的javascript

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
    $('#student_table').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sServerMethod": "POST",
        "sAjaxSource": "<?php echo base_url()?>index.php/data/all"
    } );            
} );
</script>
Run Code Online (Sandbox Code Playgroud)

检索到的JSON数据:

{"sEcho":0,"iTotalRecords":3,
"iTotalDisplayRecords":3,
"aaData":[["85","t1","1D"],["74","test475","4A"],
["777","maiz","5"]],"sColumns":"id,name,class"}
Run Code Online (Sandbox Code Playgroud)

以下是我的表格:

<table class="datatable tables" id="student_table">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Class</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="dataTables_empty">Loading data from server</td>
        </tr>
    </tbody>
</table> 
Run Code Online (Sandbox Code Playgroud)

PHP代码(点燃数据表)

$this->load->library('datatables');

$this->datatables->select('admission,name,class');
$this->datatables->from('students');
echo $this->datatables->generate();
Run Code Online (Sandbox Code Playgroud)

我正在使用codeigniter和DataTables.

为什么我会收到该错误以及如何将数据检索到表中?

Sac*_*sad 13

我也有同样的问题.问题在于:

<tr>
          <td class="dataTables_empty">Loading data from server</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

您有三个<TH>但只有一个<td> 添加两个<td>将修复您的错误.还有一件事,如果没有数据可用,它将自动显示消息,您无需显示消息.在这种情况下,您可以删除它,因为它将自动完成:

<tr>
          <td class="dataTables_empty">Loading data from server</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

为了自定义消息,请将此作为选项传递 "sEmptyTable": "Loading data from server"

$('.datatable ).dataTable({
  "bFilter": false,
   "bPaginate": false,
   "bLengthChange": false,
   "bInfo": false,
   "oLanguage": {
    "sEmptyTable": '',
    "sInfoEmpty": ''
   },
   "sEmptyTable": "Loading data from server"
 });
Run Code Online (Sandbox Code Playgroud)


Jvd*_*erg 1

您正在使用 POST 方法来获取数据。如果您遵循 php 随datatables提供的示例,则使用 GET 方法。我假设当您使用排序或搜索时,所有请求都是 GET。