注册 登录
编程论坛 J2EE论坛

jsp编写的js,怎么得到action返回的JSON的值

黄昏的王座 发布于 2013-03-16 12:11, 1005 次点击
这是我的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,请问我该怎么
5 回复
#2
hhwz2013-03-16 13:39
你用AJAX访问action  那么返回的格式必须是json格式的 而不是 return "success"
#3
黄昏的王座2013-03-16 14:15
回复 2楼 hhwz
那样的话配置文件怎么写呢?现在提示404错误了
#4
黄昏的王座2013-03-16 14:46
回复 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的值,值栈中也没有哪一项,请问这是怎么回事?
#5
hhwz2013-03-16 16:28
你转换了json值 要响应到页面上去
   success : function(data) {
                alert("aaa");
                alert(data);
            },

data 就是响应到页面的值
所以你要
return customInfor
#6
黄昏的王座2013-03-16 17:44
回复 5楼 hhwz
搞定了,还是用老办法,在后台加个out.print(infor);
谢谢了哈
1