热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

为第0行请求未知参数'0'-Requestedunknownparameter'0'forrow0

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 个解决方案

#1


1  

When using Objects as your data source, you need to use columns.data options to define which property corresponds to which column.

当使用对象作为数据源时,需要使用列。数据选项,用于定义与哪个列对应的属性。

For example:

例如:

$("#dataTable").DataTable( {
    serverSide: true,
    ajax: "systemlog/loadData",
    columns: [
       { data: "logDateTime" },
       { data: "logType" },
       { data: "source" },
       { data: "user" },
       { data: "message" }
    ]
} );

推荐阅读
author-avatar
我怀念的2502909393_663
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有