作者:我怀念的2502909393_663 | 来源:互联网 | 2023-05-19 06:55
ImtryingtousejQueryDataTableswithserver-sidePHPusingAJAX.我正在尝试使用jQuery和服务器端PHP使用AJAX。M
I'm trying to use jQuery DataTables with server-side PHP using AJAX.
我正在尝试使用jQuery和服务器端PHP使用AJAX。
My Ajax call is simple as:
我的Ajax调用很简单:
$(document).ready(function() {
$("#dataTable").DataTable( {
serverSide: true,
ajax: "systemlog/loadData",
} );
} );
And here is my PHP code:
这是我的PHP代码:
$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;
And my returned JSON is like:
我返回的JSON是:
{"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."}]}
All done but I´m getting the following error from DataTables at client side:
都做过但是我´m在客户端从datatable中得到以下错误:
DataTables warning: table id=dataTable - Requested unknown parameter '0' for row 0.
DataTables警告:表id=dataTable—请求的未知参数“0”表示第0行。
No data is shown on screen.
屏幕上没有显示数据。
1 个解决方案