I am trying to run this server side example for jquery datatable, but it keeps on giving the JSON format error.
My jsp code looks like this -
<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>
and the ajax listener's return object is created using this -
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");
o开发者_高级运维utputData.put("iTotalDisplayRecords", "3");
outputData.put("aaData", data);
Manually going to the ajax link, returns this -
{iTotalDisplayRecords=3, iTotalRecords=99, aaData=[["1","a1","a2"],["3","c1","c2"],["2","b1","b2"]], sEcho=1}
Can anyone please suggest, what I might be doing wrong here.
That doesn't look like json data that you're getting back from the call. Here is a simple example of a json formatted object.
JSON- name value pairs separated by colons, each pair separated by commas. I threw in array below for good measure.
{"xxx":1, "yyyyy": 2, "z": [1,2,3,4]}
精彩评论