我遇到了麻烦,在我的代码中发现问题。用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