2012-09-05 28 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忽略它。

相關問題