jquery – DataTables:无法读取undefined的属性’length’

前端之家收集整理的这篇文章主要介绍了jquery – DataTables:无法读取undefined的属性’length’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我理解这是一个受欢迎的问题,我已经在Stack Overflow和其他网站(包括datatables网站)上阅读了所有类似的问题.

为了澄清,我正在使用

> PHP Codeigniter
> Materliazecss

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

[{"name_en":"hello","phone":"55555555","email":"a.shouman","facebook":"https:\/\/www.facebook.com"},{"name_en":"Mahfouz","phone":"00000000","email":"m.mahfouz","facebook":null},{"name_en":"Abdelrahman",{"name_en":"ayman test","phone":"55554444",{"name_en":"Abdelrahman Mossad Shouman Bootstrap","phone":"12345678","email":"a.shouman@mail.com","facebook":"https:\/\/www.facebook.co"},{"name_en":"a.sharara","email":"a.sharara","facebook":""}]

我的HTML表格如下所示:

<table id="customer_table">
     <thead>
         <tr>
            <th>Name</th>
            <th>Contact</th>
            <th>Email</th>
            <th>Facebook</th>
         </tr>
     </thead>
</table>

这是我的document.ready功能

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

我得到的错误

Uncaught TypeError: Cannot read property ‘length’ of undefined

解决方法

它甚至更简单:juste在ajax定义中使用dataSrc:”选项,因此dataTable不期望一个对象而是一个数组:
$('#pos-table2').DataTable({
                "processing": true,"serverSide": true,"ajax":{"url":"pos.json","dataSrc":""}
            }
    );

ajax options

原文链接:https://www.f2er.com/jquery/181633.html

猜你在找的jQuery相关文章