Error Requested unknown parameter '0' for row 0 when getting PHP data
Error Requested unknown parameter '0' for row 0 when getting PHP data
cox
Posts: 1Questions: 1Answers: 0
So, I´m using server side processing with a PHP AJAX call as follows:
$(document).ready(function() {
$("#dataTable").DataTable( {
serverSide: true,
ajax: "systemlog/loadData",
} );
} );`
And my PHP code:
$logList = \Models\SysLog::all($where, $fields, $order, $direction);
$data = array();
foreach ($logList as $sysLog)
{
$data[] = array("logDateTime" => $sysLog->logDateTime,
"logType" => $sysLog->logType,
"source" => $sysLog->source,
"user" => $sysLog->user,
"message" => $sysLog->message);
}
$retData = array (
"draw" => $draw,
"recordsTotal" => count($sysLogList),
"recordsFiltered" => count($sysLogList),
"data" => $data
);
$result = json_encode($retData);
echo $result;
That results in the following ajax that leads to the title error.
{"draw":"1","recordsTotal":30,"recordsFiltered":30,"data":[{"logDateTime":0,"logType":"INFO","source":"sys","user":"sys","message":"Program start."},{"logDateTime":0,"logType":"INFO","source":"sys","user":"sys","message":"Starting handler."},{"logDateTime":0,"logType":"INFO","source":"sys","user":"sys","message":"Starting persistance updater."}]}
What am I doing wrong regarding the data formatting ? Thanks for helping...
This discussion has been closed.
Answers
The tech note that the error you are seeing should link to provides details on why this happens and how to resolve it. The manual also provides a detail overview. In short, you need to use
columns.data
to tell DataTables what data belongs in each column.Allan