0
在jquery的数据表中调用的代码是如下AJAX源的数据表不显示任何数据和没有错误消息被显示
$(document).ready(function() {
$("#tableUserList").DataTable({
"ajax": {
"url": "AdminHome.aspx/getUsersForTable",
"dataType": "json",
"cache": false,
"contentType": "application/json; charset=utf-8",
"dataSrc": "d",
"type": "GET"
},
"columns": [
{"data": "d[id]"},
{"data": "d[username]"},
{"data": "d[user_type]"},
{"data": "d[first_name]"},
{"data": "d[last_name]"},
{"data": "d[address]"},
{"data": "d[email]"},
{"data": "d[phone_no]"},
]
});
});
当我检查没有显示任何错误控制台但既不被加载到任何数据数据表。我的HTML表格是在本如下
<table id="tableUserList" class="table table-hover">
<thead>
<tr>
<th>UserID</th>
<th>Username</th>
<th>UserType</th>
<th>FirstName</th>
<th>LastName</th>
<th>Address</th>
<th>Email</th>
<th>Contact</th>
</tr>
</thead>
<tbody>
<tr>
<td>UserId</td>
<td>Username</td>
<td>UserType</td>
<td>FirstName</td>
<td>LastName</td>
<td>Address</td>
<td>Email</td>
<td>Contact</td>
</tr>
</tbody>
</table>
和我的AJAX调用返回的数据format.Showing返回的数据的一个单独的行,简单
{
"d":[
{
"id":1,
"username":"admin",
"first_name":"admin",
"last_name":"admin",
"phone_no":"1234567210",
"address":"abc",
"email":"[email protected]",
"user_type":"admin"
},
...
]
}
数据正确返回意味着我做错了什么将接收到的数据绑定到DataTable。请提出解决方案。
它是不是有效的JSON,数组不应该被引用。 – davidkonrad