我想用表中的数据库值填充数据表。下面是我的代码清单,一切似乎都正常,但返回错误“TypeError:aData is undefined”,因此未创建数据表
<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>
服务器端
function getUsers(){
$this->db->select('id,username');
$query = $this->db->get('user');
$data = $query->result();
echo json_encode($data);
}
这是json encode返回的数据
[
{"id":"6","username":"Lab23"},
{"id":"11","username":"MaryMM"}
]