I'm having troubles identify the problem in my code.
I'm doing a searching script, and I'd like to show the results in Datatable. I have a searching form that sends data to my php file and returns a json_encode of my query results, then on ajax success, I build my table passing the results in "data": response.
The query worked just fine when I was doing it without Datatables, but since I need pagination and stuff, I need it to work on Datatables.
HTML for Table:
<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 for Datatable:
$('#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" is my button for submit ofcourse, and "ricerca" is the name of my form.
The json code I get is:
{"sEcho":0,"iTotalRecords":"35036","iTotalDisplayRecords":"1","aaData":[["stuff","stuff","stuff","stuff","stuff","stuff","stuff","stuff","stuff","stuff"]]}
Error:
DataTables warning: table id=example - Requested unknown parameter '1' for row 0.