如何解决DataTable对表不起作用
我正在MVC中使用DataTable库,但是它不起作用 这是视图部分
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Id</th>
<th>Phone</th>
<th>FirstName</th>
<th>LastName</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Id</th>
<th>Phone</th>
<th>FirstName</th>
<th>LastName</th>
</tr>
</tfoot>
</table>
<script type="text/javascript">
//$(document).ready(function () {
// $('#example').DataTable();
//})
$(document).ready(function () {
GetEmployeeRecord();
})
var GetEmployeeRecord = function () {
$.ajax({
type: "Get",url: "/BasicInfo/GetCustomers",success: function (response) {
alert("success");
BindDataTable(response);
},error: function () {
alert("error");
}
})
}
var BindDataTable = function (response) {
$("#example").DataTable({
"aaData": response,"aoColumns": [
{ "mData": "Id" },{ "mData": "Phone" },{ "mData": "FirstName" },{ "mData": "lastName" }
]
});
}
这是控制器部分
public JsonResult GetCustomers()
{
SalonEntities db = new SalonEntities();
List<Customer> CustomerList = db.Customers.OrderByDescending(a => a.ID).ToList();
return Json(CustomerList,JsonRequestBehavior.AllowGet);
}
尽管控制器中的CustomerList已加载,但它返回到视图并进入jquery的error部分 什么可能是问题
解决方法
对控制器的ajax调用失败。要调试它,您可以做两件事:
警告错误
删除(引号)"
,以警告实际错误。
error: function () {
alert(error);
}
您很有可能会在控制台的开发人员工具中看到它。
检查网络标签
在“网络”标签中,您会看到错误(4XX,5XX)或类似的信息,并附有一些额外的信息(如果幸运的话)。
如果没有更多信息,并且错误500,则需要检查后端代码中的异常。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。