2012-09-05 29 views
6

当我尝试从我的数据库表中检索数据,我得到这个错误:从数据源请求的未知参数“1” 0行中的数据表

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

下面是我使用的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> 

JSON数据检索:

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

下面是我的表:

<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> 

PHP代码(点燃数据表)

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

$this->datatables->select('admission,name,class'); 
$this->datatables->from('students'); 
echo $this->datatables->generate(); 

我使用笨和数据表。

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

回答

1

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

+0

我尝试了GET和POST,但我得到了同样的错误。 – LiveEn

+0

错误必须在php部分,你能证明吗? – JvdBerg

+0

我已经添加了PHP代码(点燃datatables)的主要职位。 – LiveEn

0

夫妇的想法可能有助于...

  1. 确保从服务器响应的格式是正确的JSON,用正确的头。例如 https://stackoverflow.com/a/4064468/661584不知道有关点火器/ PHP本身,但可能是一个问题。

  2. 不知道sColumns参数是对自己有正确的,认为这是对客户的cols的重新排序......只有用SNAME用于看到 http://datatables.net/usage/columns#sNamehttp://datatables.net/usage/server-side

这样有可能被搞乱了。

  1. 如果还有其他事情,或许看看回答here ...可能会有所帮助。

好运

14

我也有同样的问题。问题就在这里:

<tr> 
      <td class="dataTables_empty">Loading data from server</td> 
</tr> 

你有三个<TH>但只有一个<td>增加两个<td>将解决您的错误。 还有一两件事,如果没有数据可用时,它会自动显示该消息你不需要显示message.In这种情况下,你可以删除这个,因为它会自动完成:

<tr> 
      <td class="dataTables_empty">Loading data from server</td> 
</tr> 

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

$('.datatable).dataTable({ 
    "bFilter": false, 
    "bPaginate": false, 
    "bLengthChange": false, 
    "bInfo": false, 
    "oLanguage": { 
    "sEmptyTable": '', 
    "sInfoEmpty": '' 
    }, 
    "sEmptyTable": "Loading data from server" 
}); 
+0

我爱你。只是花了很长时间试图弄清楚这一点。 – Chris

+0

我的代码使用colspans,希望colspans不会造成这种情况,即使它们是正确的! – Andy

0

我们遇到过类似问题...

但是,在你疯了 - 检查表中的数据。 在我们的案例中,我们的数据有填充表格的数据中使用的超链接和曲线引号 - 当数据从CSV文件中上传时,这些引号会将卷曲引号删除。 小故事是IE无法处理它,但Chrome和Firefox忽略它。

相关问题