日期:2014-05-17  浏览次数:20745 次

求指导:Jquery ajax问题
在学习jquery ajax的过程中遇到了些问题,网上找了N久没能解决。
希望各位大大指点一二。
小弟先谢过了。
JSP代码:
$(document).ready(function(){
  $("#searchdeptimg").click(function(){
var param = $("#cdepname").val();
$.ajax({
type: "post",
dataType: "json",
url: "${dynamicURL}/riskestimate/createIcreConditionSearch.action",
data: {"searchinfo":"hehe"},
success:
  function(data){
alert(data.msg);
  },
error:
  function(XMLHttpRequest, textStatus, errorThrown){
        alert("status:"+XMLHttpRequest.status);
                        alert("readyState:"+XMLHttpRequest.readyState);
                        alert("error:"+textStatus);
  }
});
  });
});
Acrion中java代码:
private String searchinfo;
public String getSearchinfo() {
       return searchinfo;
}
public void setSearchinfo(String searchinfo) {
       this.searchinfo = searchinfo;
}
HttpServletRequest rquest = this.getRequest();//父类的方法
HttpServletResponse response = this.getResponse();//父类的方法
private PrintWriter out = null;
public String execute() throws Exception {
      response.setContentType("text/html");
      response.setCharacterEncoding("UTF-8");  
      out = response.getWriter();
out.flush();
out.write("{\"msg\":\"发送成功\"}");
out.flush();  
out.close();

return SUCCESS;
}
问题来了:
1.jquery ajax传到action的值 用什么、怎么接收?
2.为什么在JS里写上dataType:"json" 就会一直走error的function呢?打印出的信息分别是status:200、readyState:4、error:parsererror。
3.如果不写dataType: "json"的话,可以返回到success的function。但是data打印出来却是整个JSP页面的html,这是为什么呢?
4.有木有ArrayList转化为json的方法呢?

真心求指导~~~


juery ajax