DataTables: 无法读取未定义的属性'length'

100

我知道这是一个常见的问题,我已经阅读了在Stack Overflow和其他站点上的所有类似的问题(包括datatables网站)。

为了澄清,我正在使用:

  • PHP Codeigniter
  • Materliazecss

我还确保正确地接收了JSON数组:

[{"name_en":"hello","phone":"55555555"},{"name_en":"hi","phone":"00000000"}]

我的HTML表格长这样:

<table id="customer_table">
     <thead>
         <tr>
            <th>Name</th>
            <th>Phone</th>
         </tr>
     </thead>
</table>

这是我的document.ready函数:

  $(document).ready(function(){
            //$('#customer_table').DataTable();
            $('#customer_table').DataTable( {
                "ajax": 'json',
                "dataSrc": "",
                 "columns": [
                    { "data": "email" },
                    { "data": "name_en" }
                ]
            });
  });

我遇到的错误是

未捕获的类型错误: 无法读取未定义的属性 'length'

12个回答

0
在我的HTML代码中,表格有两个开头的标签。我纠正了这个问题后,它完美地工作了。那个表格上我没有使用ajax。
检查具有少量值以验证的表格结构。

-2

你可以尝试检查一下你的字段,因为你正在呈现电子邮件字段,而这个字段在你的Ajax中是不可用的。

$.ajax({
  url: "url",
  type: 'GET',
  success: function(data) {
    var new_data = {
      "data": data
    };
    console.log(new_data);
  }
});


1
这个回答与他的问题无关。 - Fabio William Conceição

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接