我尝试在DataTable上使用ajax,但是我收到了这个错误.. 在这里,我解释我的代码:
脚本:
$(document).ready(function() {
$('#tblEmployee').DataTable({
"ajax": {
url: '/Employee/GetEmployees',
dataSrc: ''
},
"columns": [
{ '': 'sEmpName' },
{ '': 'sGender' }
]
});
});
JSON回归:
[{"sEmpName":"Andi","sGender":"Man"},{"sEmpName":"Mark Will","sGender":"Women"},{"sEmpName":"Edward","sGender":"Man"}]
HTML:
<table id="tblEmployee" class="table table-bordered">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.sEmpName)
</th>
<th>
@Html.DisplayNameFor(model => model.sGender)
</th>
</tr>
</thead>
</table>
我已经阅读了此文档https://datatables.net/manual/ajax,但仍然收到错误..
答案 0 :(得分:2)
我改变了我的脚本:
$(document).ready(function() {
$('#tblEmployee').DataTable({
"sAjaxSource": '/Employee/GetEmployees',
"sAjaxDataProp": "",
"aoColumns": [
{ "mDataProp": "sEmpName" },
{ "mDataProp": "sGender" }
]
});
});
它也有效。谢谢.. :))
注意: 我使用了jQuery 3.1.0和DataTables 1.10.12