struts2.1.6使用jquery的getJSON方法,查看生成JSON数据成功,但回调函数data为空,请问问什么?

[复制链接]
查看11 | 回复2 | 2011-7-5 20:01:43 | 显示全部楼层 |阅读模式
Action如下:
        private String email;
        private String content;
        private Dbdao db;
        private Map addstatus;
        private String result;
public String execute()throws Exception {
                HttpServletResponse response=ServletActionContext.getResponse();
                response.setContentType("application/json");
                addstatus= new HashMap();
                addstatus.put("email", getEmail());
                addstatus.put("content", getContent());
                JSONObject jsonobj =JSONObject.fromObject(addstatus);
               
                result=jsonobj.toString();
db=Dbdao.instance();
                db.insertStatus(email, content);
       
                return "status";
               
        }
struts2.xml如下:


/hello.jsp

       






js如下:
$(document).ready(function(){
$("#btn_status").click(function()
{$.getJSON("insertstatus.action",function(data){       
$("#info").html("");
alert(data.content);
$("#info").append("
the content is:"+data.content+"
");
}
);
}
);
}
);
生成文件如下:
"addstatus":{"content":"asd","email":"[email protected]"},"content":"asd","email":"[email protected]","result":"{\"content\":\"asd\",\"email\":\"[email protected]\"}"}
补充说明,如果alert(data)弹出[object object].如果如果访问内容返回null
无人理会么,急啊!!!!!!

回复

使用道具 举报

千问 | 2011-7-5 20:01:43 | 显示全部楼层
用FireBug设置断点看一下data的值。jQuery的早期版本,JSON方式没有效,还要用eval对返回数据做处理。...
回复

使用道具 举报

千问 | 2011-7-5 20:01:43 | 显示全部楼层
return "status";改成return SUCCESS; 要将data进行eval转换成JSON格式,因为data只是个字符串。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行