我正在尝试为jquery example运行此服务器端datatable,但它继续提供JSON格式错误。
我的jsp代码看起来像这样 -
<script>
$(document).ready(function () {
$("#companies").dataTable({
"bServerSide": true,
"sAjaxSource": "/dummySearchProposals",
"sPaginationType": "full_numbers",
"iDisplayLength":3,
"bJQueryUI": true,
});
});
</script>
<body id="dt_example">
<div id="container">
<div id="demo_jui">
<table id="companies" class="display">
<thead>
<tr>
<th>Company name</th>
<th>Address</th>
<th>Town</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
并使用此< - p>创建ajax侦听器的返回对象
String[] data1 = {"1","a1","a2"};
String[] data2 = {"2","b1","b2"};
String[] data3 = {"3","c1","c2"};
JSONArray data = new JSONArray();
data.put(data1);
data.put(data3);
data.put(data2);
outputData.put("sEcho", queryString.get("sEcho"));
outputData.put("iTotalRecords", "99");
outputData.put("iTotalDisplayRecords", "3");
outputData.put("aaData", data);
手动转到ajax链接,返回此 -
{iTotalDisplayRecords=3, iTotalRecords=99, aaData=[["1","a1","a2"],["3","c1","c2"],["2","b1","b2"]], sEcho=1}
任何人都可以建议,我在这里可能做错了。
答案 0 :(得分:0)
这看起来不像你从电话中回来的json数据。这是一个json格式化对象的简单示例。
由冒号分隔的JSON-名称值对,每对由逗号分隔。为了好的措施,我把它放在下面的数组中。
{"xxx":1, "yyyyy": 2, "z": [1,2,3,4]}