javascript - 数据表类型错误 : c is undefined

标签 javascript jquery datatables

我尝试使用 jQuery DataTables 但出现错误

TypeError: c is undefined

我不知道我的代码有什么问题,因为我可以看到 JSON 正确检索并且格式也正确,但我不知道它有什么问题导致出现上述错误。

我的 JSON:

{"Data":[{"LOGIN":10184},{"LOGIN":10214},{"LOGIN":10180},{"LOGIN":10187},{"LOGIN":10179},{"LOGIN":10280},{"LOGIN":201},{"LOGIN":10238},{"LOGIN":10296},{"LOGIN":10312}]}

和我的 DataTables 代码:

$(document).ready(function() {
    $('#tablename').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "type": "POST",
        "url": "https://test.com/api/db/select",
        "data": function ( json ) {  return JSON.stringify( { "Sql": 12 } );},
        "contentType": "application/json; charset=utf-8",
        "dataType": "json",
        "processData": true,
            beforeSend : function(xhr){
                        var access_token = sessionStorage.getItem('access_token');
                        xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
            }
        },
        "dataSrc": "Data",
        "columns": [
            { "data": "LOGIN" }
        ]
    } );
} );

最佳答案

检查是否添加了

<thead></thead>

<tbody></tbody>

我已经通过添加这些解决了这个问题。

所以基本上结构必须是这样的:

<table>
 <thead>
  <tr>
   <th></th>
   <th></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td></td>
   <td></td>
  </tr>
 </tbody>
</table>

关于javascript - 数据表类型错误 : c is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29893207/

相关文章:

jQuery - 滚动经过另一个元素后隐藏固定元素

javascript - 如何更改jquery函数变量?

javascript - 单击时使用 ajax 调用重新加载数据表数据

javascript - 动态选择单选按钮

javascript - JQUERY 自动完成功能在 chrome 和 firefox 中工作,但在 IE 中不起作用

JavaScript:检测 iframe 内的链接点击

javascript - 使用变量时背景没有动画

jquery - 仅删除 DOM JQuery 中的父元素

jquery - 即时更改设置值?

javascript - 在 AngularJS 中按数字过滤数组