TypeError: data is undefined when using datatable plugin
TypeError: data is undefined when using datatable plugin
我正在尝试使用 DataTables.I 从服务器检索数据可以在我的浏览器的网络部分查看 json 响应,在控制台中查看 well.But 它给我 类型错误:数据未定义。除了列名和 Processing.. 标签外,table 内没有显示任何内容。
Here is my Json response:
{"userList":[{"age":23,"userId":123,"user_name":"Mike"},{"age":22,"userId":345,"user_name":"John"},{"age":23,"userId":123,"user_name":"Peter"}]}
Java Script:
$(document).ready(function () {
$('#mytable').dataTable({
"processing": true,
"serverSide": true,
"ajax": "jsond",
"columns": [
{"userList": "userId"},
{"userList": "user_name"},
{"userList": "age"}
]
});
});
Html:
<table id="mytable">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
</tr>
</tfoot>
</table>
有人可以建议我摆脱这个错误的方法....
根据此页面,您的数据格式有误。
{
"data":[{"age":23,"userId":123,"user_name":"Mike"},{"age":22,"userId":345,"user_name":"John"},{"age":23,"userId":123,"user_name":"Peter"}]
}
我正在尝试使用 DataTables.I 从服务器检索数据可以在我的浏览器的网络部分查看 json 响应,在控制台中查看 well.But 它给我 类型错误:数据未定义。除了列名和 Processing.. 标签外,table 内没有显示任何内容。
Here is my Json response:
{"userList":[{"age":23,"userId":123,"user_name":"Mike"},{"age":22,"userId":345,"user_name":"John"},{"age":23,"userId":123,"user_name":"Peter"}]}
Java Script:
$(document).ready(function () {
$('#mytable').dataTable({
"processing": true,
"serverSide": true,
"ajax": "jsond",
"columns": [
{"userList": "userId"},
{"userList": "user_name"},
{"userList": "age"}
]
});
});
Html:
<table id="mytable">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
</tr>
</tfoot>
</table>
有人可以建议我摆脱这个错误的方法....
根据此页面,您的数据格式有误。
{
"data":[{"age":23,"userId":123,"user_name":"Mike"},{"age":22,"userId":345,"user_name":"John"},{"age":23,"userId":123,"user_name":"Peter"}]
}