jsp编写的js,怎么得到action返回的JSON的值
这是我的JS$("#uuu").click(function(){
var putin = $("#clientid").serializeArray();
$.ajax({
url : "creditApplyInsertAjaxAction",type : "post",dataType:"json",data : putin,timeout : 20000,// 设置请求超时时间(毫秒)。
beforeSend: function(XMLHttpRequest){
alert("uuu");
},
success : function(data) {
alert("aaa");
alert(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
})
这是我的action
public String execute() {
customP = this.custom2.showP(clientid);
customInfor = new Gson().toJson(customP);
return "success";
}
这是我的配置文件
/WEB-INF/content/credit/creditApplyInsert.jsp
customInfor
customP
但是我得到的值栈中的信息全部是NULL,我想得到的是customInfor或者是customP,请问我该怎么
搜索更多相关主题的帖子:
uuu function success action
----------------解决方案--------------------------------------------------------
你用AJAX访问action 那么返回的格式必须是json格式的 而不是 return "success"
----------------解决方案--------------------------------------------------------
回复 2楼 hhwz
那样的话配置文件怎么写呢?现在提示404错误了 ----------------解决方案--------------------------------------------------------
回复 2楼 hhwz
public String execute() {System.out.println("id = " + this.clientid);
System.out.println("service = " + this.custom2 + "---");
customP = this.custom2.showP(clientid);
System.out.println("========" + this.custom2.showP(this.clientid));
customInfor = JSONObject.fromObject(customP);
System.out.println(customInfor.toString());
return "success";
}
JSON customInfor;
我更改了action,没有错误,能success,但是不能得到customInfor的值,值栈中也没有哪一项,请问这是怎么回事?
----------------解决方案--------------------------------------------------------
你转换了json值 要响应到页面上去
success : function(data) {
alert("aaa");
alert(data);
},
data 就是响应到页面的值
所以你要
return customInfor
----------------解决方案--------------------------------------------------------
回复 5楼 hhwz
搞定了,还是用老办法,在后台加个out.print(infor); 谢谢了哈
----------------解决方案--------------------------------------------------------