[英]DataTables error 500 when waiting for large amount of data
我有一个使用Knockout.JS和Knockout-mapper.js的DataTable实现。 我使用ajax调用获取数据,并且可以很好地处理5k记录。 但是当我尝试说10万条记录时,我得到了
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
谁能指出我正确的方向,我如何在网格中获取大量数据。
页:
<script type="text/javascript">
$(function () {
function viewModel(data) {
var self = this;
ko.mapping.fromJS(data, {}, self);
}
$.ajax({
url: "@Url.Action("GetRecordsJsonResultAll")", success: function (data) {
ko.applyBindings(new viewModel(data));
$("#items").DataTable({
responsive: true
});
}
});
});
</script>
<div class="row">
<table id="items" class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
</tr>
</thead>
<tbody data-bind="foreach: items">
<tr>
<td><span data-bind="text: $data.Id"></span></td>
<td><span data-bind="text: $data.FirstName"></span></td>
<td><span data-bind="text: $data.LastName"></span></td>
<td><span data-bind="text: $data.Email"></span></td>
</tr>
</tbody>
</table>
</div>
控制器的Json结果(100k结果)
public virtual JsonResult GetRecordsJsonResultAll()
{
var userBusinessLogic = InterfaceResolver.ResolveWithTransaction<IUserBusinessLogic>();
var records = userBusinessLogic.GetAll().Select(x => new
{
x.Id,
x.FirstName,
x.LastName,
x.Email
}).OrderBy(i => i.Id);
var data = Json(new
{
max = records.Count(),
items = records
}, JsonRequestBehavior.AllowGet);
return data;
}
感谢您的任何帮助。
您可能达到了MaxJsongLength
限制。 尝试将操作方法更改为
public virtual ActionResult GetRecordsJsonResultAll()
{
var userBusinessLogic = InterfaceResolver.ResolveWithTransaction<IUserBusinessLogic>();
var records = userBusinessLogic.GetAll().Select(x => new
{
x.Id,
x.FirstName,
x.LastName,
x.Email
}).OrderBy(i => i.Id);
var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
var data = new
{
max = records.Count(),
items = records
};
var result = new ContentResult
{
Content = serializer.Serialize(data),
ContentType = "application/json"
};
return result;
}
同样,使用敲除映射映射100000
条记录可能会导致整个网页的用户体验缓慢/无响应。 使用分页或按需加载数据。 您可以使用测试
function viewModel(data) {
var self = this;
console.log(data, "from server")
self.items = data.items.slice(0,1000);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.