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);
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!