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