我遇到了麻煩,在我的代碼中發現問題。用php發送json填充數據表
我正在做一個搜索腳本,我想在Datatable中顯示結果。我有一個搜索表單,將數據發送到我的php文件並返回查詢結果的json_encode,然後在ajax成功時,我構建了我的表,將結果傳遞給「data」:response。
查詢工作得很好,當我沒有Datatables,但因爲我需要分頁和東西,我需要它在Datatables上工作。
爲HTML表:
<div id="results">
<table id="example" class="display compact hover stripe" cellspacing="0" width="100%">
<thead>
<th>Cognome</th>
<th>Nome</th>
<th>Telefono</th>
<th>Provincia</th>
<th>Tipo Cliente</th>
<th>Amministrazione</th>
<th>Stato</th>
<th>Fonte</th>
<th>Data Ricezione</th>
<th></th>
</thead>
</table>
</div>
的JavaScript數據表:
$('#submit_src').on("click", function() {
$.ajax({
data: $("#ricerca").serialize(),
type: $("#ricerca").attr('method'),
url: $("#ricerca").attr('action'),
success: function(response) {
$('#example').dataTable({
"data": response,
"sPaginationType": "listbox",
"bFilter": false,
"jQueryUI": true,
"processing": true,
'iDisplayLength': 25,
});
}
});
return false;
});
「submit_src」 是我的按鈕提交ofcourse和 「ricerca」 是我的表單的名稱。
JSON的代碼中,我得到的是:
{"sEcho":0,"iTotalRecords":"35036","iTotalDisplayRecords":"1","aaData":[["stuff","stuff","stuff","stuff","stuff","stuff","stuff","stuff","stuff","stuff"]]}
錯誤:
DataTables warning: table id=example - Requested unknown parameter '1' for row 0.
對不起,它沒有工作。提交表單後,我添加了從警報中獲得的錯誤,因此更容易進行調試。 – Dankorw
將'response'寫入'response ['aaData']'時會發生什麼? – Tomanow
錯誤未顯示,但該表未填充。警報響應['aaData']顯示'未定義'。 – Dankorw