这是我的javascript。我试图从getData.jsp获取一个json对象。但这个帖子不起作用。 ajax没有调用getData.jsp页面。请帮帮我,我不知道我在哪里做错了。
"
var queryObject="";
var queryObjectLen="";
$.ajax({
url :'getData.jsp',
type :'POST',
dataType:'json',
success:function(data) {
queryObject = eval('(' + JSON.stringify(data) + ')');
queryObjectLen = queryObject.empdetails.length;
},
error : function(xhr, type) {
alert('server error occoured')
}
});
"
这是我的getData.jsp
"
<%@ page import =" com.mydb" %GT;
<%@ page import =" org.json.JSONObject" %GT;
<%@ include file =" ../../../ lib / util.inc" %GT;
<%
log.debug("out.jsp1");
mydb db = null;
List<JSONObject> empdetails = new LinkedList<JSONObject>();
JSONObject responseObj = new JSONObject();
try {
log.debug("out.jsp");
db = new mydb(application);
PreparedStatement p_stmt = null;
ResultSet rs = null;
String mySql2 = "select category as category, kb_sum as KB_SUM FROM mytable ";
PreparedStatement p_stmt = db.getPreparedStatement(mySql2);
rs = db.executeQuery(p_stmt);
JSONObject empObj = null;
while (rs.next()) {
String name = rs.getString("category");
int empid = rs.getInt("KB_SUM");
empObj = new JSONObject();
empObj.put("name", name);
empObj.put("empid", empid);
empdetails.add(empObj);
}
responseObj.put("empdetails", empdetails);
out.print(responseObj.toString());
rs = null;
}
catch (Exception e) {
String errorStr = e.getMessage();
log.error(errorStr);
out.println(formatPageError(e));
}
finally {
if (db != null) {
db.freeConnection();
db = null;
}
}
%>
&#34;
答案 0 :(得分:0)
类型的帖子,因为你直接调用了一个jsp页面。 尝试删除它。