我正在尝试使用 JSP、Jquery 和 AJAX 编写一个简单的应用程序来获取和显示页面上的数据。
这是我的ajax函数:
$.ajax({
type:"POST",
url:"interface_load_status_page.jsp",
data:dataString,
dataType:"json",
success: function(data, textStatus, jqXHR){
$("#response").html("");
$("#response").append(data);
},
});
只要 dataType 设置为“text”,该 ajax 调用就可以正常工作。不幸的是,当它设置为 json 时,我需要它工作。这是ajax函数调用的JSP的代码
<%
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
String date = request.getParameter("date");
System.out.println("Date: "+date);
if (date != null) {
DBAccess acc = new DBAccess();
ArrayList<InterfaceLoadStatus> loadStatus = acc
.loadStatusQuery(date);
//System.out.println(loadStatus);
out.println(Utils.getJSONLoadStatus(loadStatus));
}
%>
JSP 所做的是将查询结果发送到 oracle 数据库并将其转换为 JSON 格式,如下所示:
{"success":true,"interfaceloadstatus":[{"bType":"COC","start":"2013-04-22 03:30:10.0","end":"2013-04-22 04:35:38.0","exe":"01:05:28","handOff":"Y"},{"bType":"DST","start":"2013-04-22 00:10:09.0","end":"2013-04-22 00:23:17.0","exe":"00:13:08","handOff":"Y"},{"bType":"HTL","start":"2013-04-22 00:10:10.0","end":"2013-04-22 01:17:14.0","exe":"01:07:04","handOff":"Y"},{"bType":"RC","start":"2013-04-22 00:10:11.0","end":"2013-04-22 00:45:17.0","exe":"00:35:06","handOff":"Y"},{"bType":"AIR","start":"2013-04-22 03:00:16.0","end":"2013-04-22 04:03:58.0","exe":"01:04:42","handOff":"Y"},{"bType":"VP","start":"2013-04-22 03:00:16.0","end":"2013-04-22 04:03:58.0","exe":"01:04:42","handOff":"Y"},{"bType":"AIR-IAR","start":"2013-04-22 09:45:06.0","end":"2013-04-22 10:24:51.0","exe":"00:40:45","handOff":"Y"}]}
好的,现在 JSON 输出已修复,但 JQuery ajax 函数仍然无法识别它