DataTables卡在处理数据上,json_encode SQL - PHP


DataTables stuck on processing data, json_encode SQL - PHP

当尝试使用 PHP 中的 json_encode 将数据从 SQL 放入数据表时,该表只是继续显示"正在处理..."

我的控制台日志显示:

捕获的类型错误:未定义不是函数 高图表.js:17(匿名功能) 高图表.js:17(匿名) 函数)高图表.js:308 XHR 完成加载:开机自检 "http://website.com/data.php"。jquery.js:4 uncatch TypeError: 无法读取未定义的属性"长度" jquery.dataTables.js:2673_fnAjaxUpdateDraw jquery.dataTables.js:2673(匿名函数) jquery.dataTables.js:2519baseAjax.success jquery.dataTables.js:2443m.回调.j jquery.js:2m.Callbacks.k.fireWith jquery.js:2x jquery.js:4m.ajaxTransport.send.b jquery.js:4XMLHttpRequest.send (async)m.ajaxTransport.send jquery.js:4m.extend.ajax jquery.js:4_fnBuildAjax jquery.dataTables.js:2495_fnAjaxUpdate jquery.dataTables.js:2515_fnDraw jquery.dataTables.js:1982_fnReDraw jquery.dataTables.js:2101_fnInitialise jquery.dataTables.js:3276(匿名函数) jquery.dataTables.js:6510m.extend.each jquery.js:2m.fn.m.each jquery.js:2DataTable jquery.dataTables.js:6041(匿名函数) 数据表:176m.Callbacks.j jquery.js:2m.Callbacks.k.fireWith jquery.js:2m.extend.ready jquery.js:2J jquery.js:2

我的索引.php是这样的:

<table id="table_id" class="display">
    <thead>
        <tr>
            <th>_RowNumber</th>
            <th>DNumber</th>
            <th>ItemNumber</th>
        </tr>
    </thead>

</table>

<script>
$(document).ready(function() {
    $('#table_id').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "<?php echo url(); ?>/new/data.php",
            "type": "POST"
        },
        "columns": [
            { "data": "_RowNumber" },
            {"data": "DNumber"},
            { "data": "ItemNumber" }
        ]
    } );
} );
</script>

而数据.php是这样的:

<?php
$SQL = "SELECT *
FROM   (SELECT Row_number()
                 OVER (
                   ORDER BY _sys_id ) AS _RowNumber,
               *
        FROM   (SELECT PList.deliverynumber AS DNumber,
                       PLine.picklistnumber,
                       PLine.picklistsuffix,
                       itemnumber,
                       fromlocation,
                       expectedquantity,
                       pickedquantity,
                       currentlocation,
                       ordernumber,
                       orderline,
                       PLine.complete,
                       PLine.insertdate,
                       itemdescription,
                       PList.complete       AS StatusCode,
                       PList.complete       AS Description,
                       PList.id             AS _SYS_ID
                FROM   picklist PList
                       JOIN pickline PLine
                         ON PList.picklistsuffix = PLine.picklistsuffix
                            AND PList.picklistnumber = PLine.picklistnumber) AS
               LIST_TABLE
        WHERE  1 = 1) AS tmp_rows
WHERE  1 = 1
       AND _RowNumber BETWEEN 1 AND 10  
        ";

$Query = $pdo->prepare($SQL);
$Query->execute();
$rows = array();
foreach ($pdo->query($SQL) as $row) {
    $rows[] = $row;

}
print json_encode($rows);
?>

导航到数据时的结果.php如下所示:

    [{"_RowNumber":"1","0":"1","DNumber":"0800","1":"0800","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"2","0":"2","DNumber":"0999","1":"0999","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"3","0":"3","DNumber":"3333","1":"3333","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"4","0":"4","DNumber":"1221","1":"1221","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"5","0":"5","DNumber":"6665","1":"6665","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"6","0":"6","DNumber":"7764","1":"7764","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"7","0":"7","DNumber":"3322","1":"3322","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"8","0":"8","DNumber":"1221","1":"1221","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"9","0":"9","DNumber":"1997","1":"1997","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"},
{"_RowNumber":"10","0":"10","DNumber":"1696","1":"1696","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}]

我需要更改哪些内容才能在数据表中显示的数据?https://datatables.net/

如果你也使用后台页面,也许你可以这样解决这个问题: 当你返回分页信息的数据结构时,可以将返回的sEcho重置为0,像这样: 例如:

dataSource.setsEcho(0);//I try set 0,It's work for me,you can try
dataSource.setAaData(tempList);
dataSource.setiTotalDisplayRecords(totalNum);
dataSource.setiTotalRecords(totalNum);

我发现问题是我必须使用

$rows['aaData'][]

而不仅仅是

$rows[]

在 foreach() 语句中

请参考

此链接获取答案.http://legacy.datatables.net/usage/server-side只需使用sAjaxDataProp配置项即可修复它