Jquery 执行任何JSON代码时获取Datatables的JSON格式错误
我使用jquerydatatables和ajax调用来获取服务器数据。我过去成功地做到了这一点。这次我尝试的新方法是使用fnServerParams传递3个参数 在jsp中,我有:Jquery 执行任何JSON代码时获取Datatables的JSON格式错误,jquery,spring,rest,datatables,Jquery,Spring,Rest,Datatables,我使用jquerydatatables和ajax调用来获取服务器数据。我过去成功地做到了这一点。这次我尝试的新方法是使用fnServerParams传递3个参数 在jsp中,我有: <script> <%--Initializes the datatable --%> var userNameJs = "${userName}"; var startDateJs = "${startDate}"; var endDateJs = "${en
<script>
<%--Initializes the datatable --%>
var userNameJs = "${userName}";
var startDateJs = "${startDate}";
var endDateJs = "${endDate}";
$(document).ready(function() {
var oTable = $('#userSearchItems')
.dataTable(
{
"bProcessing": true,
"iCookieDuration": 3600,
"bPaginate" : true,
"bServerSide": true,
"sPaginationType": "bootstrap",
"aaSorting":[[0,'asc']],
"sAjaxSource": '/kb/report/view/searchesByUserOverDatesAjax/{userName}/{startDate}/{endDate}',
"fnServerParams": function (aoData) {
aoData.push({ "name": "userName", "value": userNameJs});
aoData.push({ "name": "startDate", "value": startDateJs});
aoData.push({ "name": "endDate", "value": endDateJs});
}
});
});
</script>
<table style="width: 100%; table-layout: fixed;" class="zebra-striped bordered-table" id="userSearchItems">
<thead>
<tr>
<th>When Entered</th>
<th >Search Term</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td style="word-wrap: break-word"></td>
</tr>
</tbody>
</table>
我得到一个弹出错误:
DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的
但是searchesByUserOverDates()方法永远不会执行。在FireBug/Net中,它显示我从HTTP调用中收到了一个200OK,参数发送正常,但我的sysout和debug断点从未被命中
它似乎没有分派该方法。我在日志或js错误控制台中没有发现错误
我看到这个错误消息pre-JQuery 1.4存在一些pre-JQuery问题,但我们现在是1.8
谢谢你的帮助啊,有些蠢事。。。java方法parm末尾的额外{ 现在它可以工作了。有趣的是,编译器或SpringMVC从来没有发现这一点 干杯
@RequestMapping(value="/searchesByUserOverDatesAjax/{userName}/{startDate}/{endDate}{", method=RequestMethod.GET)
public @ResponseBody String searchesByUserOverDates(@PathVariable("userName") String userName,
@PathVariable("startDate") String startDate, @PathVariable("endDate") String endDate) {
System.out.print("HERE IN AJAX");
JSONObject result = new JSONObject();
JSONArray array = new JSONArray();