【发布时间】:2018-12-13 05:26:46
【问题描述】:
我正在尝试实现服务器端数据表,但它会抛出 Invalid JSON format 错误。
CDN
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
HTML
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>EmployeeCode</th>
<th>EmployeeName</th>
<th>ManagerName</th>
<th>DesignationName</th>
</tr>
</thead>
</table>
JS
<script>
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "/api/url",
"columns": [
{ data: "EmployeeCode" },
{ data: "EmployeeName" },
{ data: "ManagerName" },
{ data: "DesignationName" }
],
} );
} );
</script>
JSON
{
"Results":[{"EmployeeCode": "12345"}], // This is just a sample of data
"CurrentPage": 1,
"PageCount": 42,
"PageSize": 10,
"RecordCount": 417
}
【问题讨论】:
-
您的JSON数据不清楚,能否更新完整的完整数据。
-
看起来
EmployeeCode缺少引号 - JSON 中需要它们 -
@ic3b3rg 这个数据是机密的,我不能在这里发布,但我可以向你保证,数据是正确的 JSON 格式,带引号。
-
让我把你介绍给我的朋友jsonlint.com
-
@Lukman 我已经在json.parser.online.fr 上测试过这个 JSON DATA,它不会在这里抛出任何错误
标签: javascript html css json datatable