Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery datatables包含空表头_Javascript_Jquery_Json_Datatable - Fatal编程技术网

Javascript jquery datatables包含空表头

Javascript jquery datatables包含空表头,javascript,jquery,json,datatable,Javascript,Jquery,Json,Datatable,我试图使用jquery插件通过PHP脚本返回的JSON对象填充html表。关于datatables插件中json对象和选项的命名,我有点困惑。传回json对象,如下所示: echo json_encode(array('data'=>$res)); 收益率: Uncaught TypeError: Cannot read property 'length' of undefined 将数据更改为aaData时,成功填充表,但没有标题 有几篇fourm帖子提到json对象必须作为aaD

我试图使用jquery插件通过PHP脚本返回的JSON对象填充html表。关于datatables插件中json对象和选项的命名,我有点困惑。传回json对象,如下所示:

echo json_encode(array('data'=>$res));
收益率:

Uncaught TypeError: Cannot read property 'length' of undefined 
将数据更改为
aaData
时,成功填充表,但没有标题

有几篇fourm帖子提到json对象必须作为aaData返回,但是他们网站上的datatables示例文档给出了一个名为with data的json对象

这是我当前的客户端代码,我相对确定我的服务器端是正确的

$('document').ready(function(){
    $('#result').dataTable({
        "ajax": {
            'url' : 'ppmAlarms.php',

        },

        "columns": [
            { "data": "location" },
            {"data" : "descAndType" },
            {"data" : "timestamp"}
        ]
    });

    });
JSON结构如下:

{
  "aaData": [
    {
      "location": "loc1",
      "descAndType": "desc1",
      "timestamp": "2014-08-20 11:34:10"
    }
]
}

刚意识到我只需在AD中指定我自己的列标题,它们不会被填充:

<thead>
      <tr>
         <th>Name</th>
         <th>Position</th>
         <th>Office</th>
         <th>Extn.</th>
         <th>Start date</th>
         <th>Salary</th>
     </tr>
</thead>

名称
位置
办公室
Extn。
开始日期
薪水

我也在挠头。