dougong9987 2016-11-21 22:41
浏览 309

DataTables:Uncaught TypeError:无法读取未定义的属性“错误”

Here's my HTML:

<table id="mens-clubs" class="display" cellspacing="0" role="grid" data-page-length="50">
    <thead>
        <tr>
            <th width="0">ID</th>
            <th width="20%">Club</th>
            <th width="20%">City</th>
            <th width="20%">State</th>
            <th width="20%">Metro</th>
            <th width="20%">Union</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th width="0">ID</th>
            <th width="20%">Club</th>
            <th width="20%">City</th>
            <th width="20%">State</th>
            <th width="20%">Metro</th>
            <th width="20%">Union</th>
        </tr>
    </tfoot>
    <tbody></tbody>
</table>

Here's my JS:

$(document).ready(function() {
    $('#mens-clubs').DataTable({
        'ajax': {
            'url': '/my/data/path/src.php',
            'dataSrc': 'data'
        },
        'columns': [
            { 'data': 'id' },
            { 'data': 'clubName' },
            { 'data': 'city' },
            { 'data': 'state' },
            { 'data': 'metroArea' },
            { 'data': 'unionName' }
        ],
        'processing': true,
        'dom': '<"row"<"small-24 column"B>><"row"<"large-8 columns"<"row filter-wrapper"<"columns small-24"f>>><"large-16 columns right"p>>' + 't' + '<"row"<"small-24 columns"p>>',
        'buttons': [ 'copy', 'excel', 'csv', 'pdf', 'print' ],
        'searching': true,
        'language': {
            'search': '',
            'searchPlaceholder': 'Search Clubs'
        },
        'pagingType': 'full_numbers',
        'scrollY': '50vh',
        'scrollCollapse': true,
        'deferRender': true
    });
});

Here are the contents of my src.php file:

{
  "data": [{
    "id": "3",
    "clubName": "Alpha Steelers",
    "city": "Alpha",
    "state": "UT",
    "metroArea": "",
    "unionName": "Rocky Mountain"
  }, {
    "id": "5",
    "clubName": "Beta of Aspen",
    "city": "Beta",
    "state": "CO",
    "metroArea": "",
    "unionName": "Rocky Mountain"
  }, {
    "id": "6",
    "clubName": "Gamma Highlanders",
    "city": "Gamma",
    "state": "CO",
    "metroArea": "",
    "unionName": "Rocky Mountain"
  }]
}

My data file is successfully retrieved via GET every time, however, I get this error immediately following it's successful retrieval:

Uncaught TypeError: Cannot read property 'error' of undefined

The line the error references inside DataTables.js is 79406. It is inside the _fnBuildAjax() function and is as follows:

enter image description here

Has anyone ever come across this error or have any idea what this error is referring to? I've run my src.php file through JSONLinter and it is valid. Any help would be greatly appreciated.

  • 写回答

1条回答

  • douwu5428 2016-11-21 22:55
    关注

    Your json feed is missing some info. Jquery will send down a "draw" number and that needs to be fed back. You need the total and filtered as well as the data.

    $complete = array("draw" => $this->request->query['draw'],
                'recordsTotal' => $total,
                "recordsFiltered" => $filtered,
                "data" => $output);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题