数据表服务器端脚本

Datatable server-side script

我发现这段代码看起来对某些人有用,

$dataArr['aaData'] = Array();
while($row = $res->fetch_assoc()){
$r = Array();
foreach($row as $key=>$value){
    $r[] = "$key $value";
}
$dataArr['aaData'][] = $r;} 
header('Content-Type: application/json');
echo json_encode($dataArr);
/* The output will be of the form, 
{"aaData": [ [
[
   "colname data"
   ...
],
 ] */

但我收到错误消息“Table id =datos 无效 json 响应。

我的数据表列与我的数据库列的名称不同,我不确定如何处理。 这是我的 js :

   $(document).ready(function() {
function getCpAndVille(data, type, dataToSet) {
return data.cp + " " + data.ville;
}
$('#datos').dataTable({
 "order": [[ 3, "desc" ]],
 "bProcessing": true,
"sAjaxSource": 'ajx/datatable_process_search.php',
"aoColumnDefs": [
                  { "sName": "Réf.", "aTargets": [ 0 ] },
                  { "sName": "Poste", "aTargets": [ 1 ] },
                  { "sName": "Type de contrat", "aTargets": [ 2 ] },
                  { "sName": "Date de publication", "aTargets": [ 3 ]},
                  { "sName": "Lieu", "aTargets": [ 4 ], "mData": getCpAndVille  },
                  { "sName": "Descriptif", "aTargets": [ 5 ] }
                ],

谁能告诉我应该使用的正确 php 代码,因为很难找到它,而且我不理解 http://www.datatables.net/examples/data_sources/server_side.html[=13= 中给出的示例]

提前致谢。

控制台网络 --> {"aaData":[["job_id 9261","job_intitule Assistant Achats","job_contrat Int\u00e9rim","job_date_insertion 2015-02-20","cp 06110","job_ville 19"],等等...

对于那些正在寻找包含 JOIN 的服务器端脚本的人 table

https://www.daniweb.com/web-development/php/threads/467455/convert-datatables-to-server-side-processing