ajax - DataTables 警告:table id=example - 从服务器分页时 JSON 响应无效
问题描述
这是我的桌子
<table id="example" class="display" style="width: 100%">
<thead>
<tr>
<th>latitude</th>
<th>longitude</th>
</tr>
</thead>
<tfoot>
<tr>
<th>latitude</th>
<th>longitude</th>
</tr>
</tfoot>
</table>
这是我的脚本
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" />
<script>
$(document).ready(function () {
$(document).ready(function () {
$('#example').DataTable({
"processing": true,
"serverSide": true,
"info": true,
"stateSave": true,
"lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]],
"ajax": {
"url": "Default3.aspx/GetRouteName",
"type": "GET"
},
"columns": [
{ "data": "latitude" },
{ "data": "longitude" }
],
"order": [[0, "asc"]]
});
});
});
</script>
在页面的末尾,我正在加载以下脚本
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
这是我的服务器
[WebMethod]
public static string GetRouteName()
{
List<location> b = new List<location>();
for (int i = 0; i < 1000; i++)
{
location l = new location();
l.latitude = 1233;
l.longitude = 123123;
b.Add(l);
}
bise bb = new bise();
bb.data = b;
bb.draw = 3;
bb.recordsFiltered = 1000;
bb.recordsTotal = 1000;
return JsonConvert.SerializeObject(bb);
}
我不断得到DataTables warning: table id=example - Invalid JSON response
我已经尝试了这么多周转但同样的问题,我所需要的只是能够从服务器分页数据表,因为我有大数据,但 ajax 调用甚至没有触发,请从服务器引用此链接数据表
解决方案
[WebMethod]
public static string GetRouteName()
{
List<location> b = new List<location>();
for (int i = 0; i < 1000; i++)
{
location l = new location();
l.latitude = 1233;
l.longitude = 123123;
b.Add(l);
}
return JsonConvert.SerializeObject(b);
}
你能试试这个吗?它在工作吗?
推荐阅读
- laravel - 提交后如何从弹出窗口中清空输入字段-Vue-laravel?
- c++ - 使用 unordered_map 确定两个字符串是否是字谜
- sql - 过程在触发器中不起作用。没有触发器,系统程序可以正常工作
- c# - 获取错误 Year、Month 和 Day 参数描述了无法表示的 DateTime 异常
- c# - NAudio 不向我的耳机输出声音,只向我的扬声器输出声音
- c# - 在一条线上画一个圆圈
- geometry - 如何从 3 个坐标中获取矩形的 4 个坐标?
- node.js - 将 refPath 与猫鼬一起使用时,正确的输入是什么?
- php - inline-block 元素只是流出而不是进入下一行
- ios - 类型“UIPageViewController.OptionsKey”(又名“NSString”)没有成员“interPageSpacing”