简体   繁体   English

数据表TypeError:aData未定义

[英]Datatables TypeError: aData is undefined

I want to populate datatables with database values in a table. 我想用表中的数据库值填充数据表。 Below is my code listing, everything seems to be ok but an error is returned "TypeError: aData is undefined" so datatables is not created 下面是我的代码清单,一切似乎正常,但返回错误“ TypeError:aData未定义”,因此未创建数据表

<script type="text/javascript">
$(document).ready(function() {
    $('#listax').dataTable({
        "bProcessing": true,
        "bLengthChange": true,
        "bFilter": true,
        "bSort": true,
        "bInfo": true,
        "bAutoWidth": true,
        "bServerSide": true,
        "sServerMethod": "POST",
        "sAjaxSource": "<?php echo base_url(); ?>ajax_live/getUsers",
        "aoColumns": [
            null,
            null //put as many null values as your columns
        ]
    });
});
</script>

<table id="listax"></table>

Server side 服务器端

 function getUsers(){
     $this->db->select('id,username');
     $query = $this->db->get('user');
     $data = $query->result();
     echo json_encode($data); 
 }

This is the data returned by json encode 这是json编码返回的数据

[
    {"id":"6","username":"Lab23"},
    {"id":"11","username":"MaryMM"}
]

When I have done this I have had to define the columns. 完成此操作后,我必须定义列。
Example array being sent back; 示例数组被发回;

Array
(
    [0] => stdClass Object
        (
            [id] => 6
            [username] => "Lab23"
        )
    [1] => stdClass Object
        (
            [id] => 11
            [username] => "MaryMM"
        )
)

So if your json encoded array has key values of id and username the datatables would have the following segment in it. 因此,如果您的json编码的数组具有idusername的键值,则数据表中将包含以下段。

$(document).ready(function() {
    $('#listax').dataTable({
        "bProcessing": true,
        "bLengthChange": true,
        "bFilter": true,
        "bSort": true,
        "bInfo": true,
        "bAutoWidth": true,
        "bServerSide": true,
        "sServerMethod": "POST",
        "sAjaxSource": "<?php echo base_url(); ?>ajax_live/getUsers",
        "aoColumns":[
            {"mDataProp":"id"},
            {"mDataProp":"username"}
        ]
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据表:TypeError:dtSettings未定义 - Datatables : TypeError: dtSettings is undefined 数据表(行详细信息):未被捕获的TypeError:无法读取未定义的属性&#39;style&#39; - Datatables (Row Details): Uncaught TypeError: Cannot read property 'style' of undefined jQuery DataTables:未捕获的TypeError:无法读取未定义的属性“mData” - jQuery DataTables: Uncaught TypeError: Cannot read property 'mData' of undefined 数据表页脚错误:未捕获的类型错误:无法设置未定义的属性“nTf” - Datatables footer error: Uncaught TypeError: Cannot set property 'nTf' of undefined TypeError:使用jQuery Datatables Library时未定义oColumn - TypeError: oColumn is undefined When Using jQuery Datatables Library 数据表:未捕获的TypeError:无法读取未定义的属性&#39;parentNode&#39; - Datatables: Uncaught TypeError: Cannot read property 'parentNode' of undefined 数据表:未捕获的TypeError:无法读取未定义的属性“错误” - DataTables: Uncaught TypeError: Cannot read property 'error' of undefined 未捕获的TypeError:数据表 - Uncaught TypeError: Datatables javascript jQuery datatables undefined不是函数 - javascript jquery datatables undefined is not a function jQuery datatables - 未捕获的TypeError:a.charAt不是函数 - jQuery datatables - Uncaught TypeError: a.charAt is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM