//初始加载页面时
$(document).ready(function(){
?//为获取单个值的按钮注册鼠标单击事件
?$("#getMessage").click(function(){
??$.getJSON("jsontest!returnMessage.action",function(data){
???//通过.操作符可以从data.message中获得Action中message的值
???$("#message").html("<font color='red'>"+data.message+"</font>");
??});
?});
?//为获取UserInfo对象按钮添加鼠标单击事件
?$("#getUserInfo").click(function(){
??$.getJSON("jsontest!returnUserInfo.action",function(data){
???//清空显示层中的数据
???$("#message").html("");
???//为显示层添加获取到的数据
???//获取对象的数据用data.userInfo.属性
???$("#message").append("<div><font color='red'>用户ID:"+data.userInfo.userId+"</font></div>")
????????? .append("<div><font color='red'>用户名:"+data.userInfo.userName+"</font></div>")
????????? .append("<div><font color='red'>密码:"+data.userInfo.password+"</font></div>")
??});
?});
?//为获取List对象按钮添加鼠标单击事件
?$("#getList").click(function(){
??$.getJSON("jsontest!returnList.action",function(data){
???//清空显示层中的数据
???$("#message").html("");
???//使用jQuery中的each(data,function(){});函数
???//从data.userInfosList获取UserInfo对象放入value之中
???$.each(data.userInfosList,function(i,value){
????$("#message").append("<div>第"+(i+1)+"个用户:</div>")
?????? .append("<div><font color='red'>用户ID:"+value.userId+"</font></div>")
????????? .append("<div><font color='red'>用户名:"+value.userName+"</font></div>")
????????? .append("<div><font color='red'>密码:"+value.password+"</font></div>");
???});
??});
?});
?//为获取Map对象按钮添加鼠标单击事件
?$("#getMap").click(function(){
??$.getJSON("jsontest!returnMap.action",function(data){
???//清空显示层中的数据
???$("#message").html("");
???//使用jQuery中的each(data,function(){});函数
???//从data.userInfosList获取UserInfo对象放入value之中
???//key值为Map的键值
???$.each(data.userInfosMap,function(key,value){
????$("#message").append("<div><font color='red'>用户ID:"+value.userId+"</font></div>")
????????? .append("<div><font color='red'>用户名:"+value.userName+"</font></div>")
????????? .append("<div><font color='red'>密码:"+value.password+"</font></div>");
???});
??});
?});
?//向服务器发送表达数据
?$("#regRe").click(function(){
??//把表单的数据进行序列化
??var params = $("form").serialize();
??//使用jQuery中的$.ajax({});Ajax方法
??$.ajax({
???url:"jsontest!gainUserInfo.action",
???type:"POST",
???data:params,
???dataType:"json",
???success:function(data){
????//清空显示层中的数据
???$("#message").html("");
???//为显示层添加获取到的数据
???//获取对象的数据用data.userInfo.属性
???$("#message").append("<div><font color='red'>用户ID:"+data.userInfo.userId+"</font></div>")
????????? .append("<div><font color='red'>用户名:"+data.userInfo.userName+"</font></div>")
????????? .append("<div><font color='red'>密码:"+data.userInfo.password+"</font></div>")
???}
??});
?});
});
详细解决方案
struts2回到JSON,jquery解析JSON(返回的可能是LIST,MAP,对象,单个值)
热度:188 发布时间:2012-10-25 10:58:57.0
相关解决方案
- jquery 获取jsp页面的id解决方法
- struts2.xml的action中的result报错,该怎么处理
- (Struts2+JSON+Ajax) XMLHttpRequest ==500如何解决
- struts2 对象属性流入不进去, 报错:target is null for setProperty(null, "x" [Ljava.lang.Stri
- request.setAttribute("list" "''");该怎么解决
- json 解析有关问题
- Struts2 <select>上拉框 回显有关问题
- struts2 添加和修改怎么在一个jsp页面实现
- struts2 查询输出的有关问题
- Hibernate 的query.list()的有关问题
- 零配置的有关问题(struts2+Hibernate)
- struts2 神奇有关问题,太神奇了!
- struts2 的<s:iterator>标签展示未完全初始化的数组出现奇怪的有关问题
- jquery,二维数组取值。解决办法
- 求jquery.form.js+jquery.validate.min.js 用ajax提交表单的代码范例
- struts2 文件下传有关问题
- jquery 提交form表单不用插件的那种 如何提交
- struts2+ajax请求失败,帮忙看一上
- struts2-json中诠注@JSON(deserialize=false)是什么用?不是阻止JSON反序列化成JAVA对象吗?求解
- struts2 循环累加属性值有关问题
- struts2,hibernate,spring3 常用框架的API CHM版本,该怎么处理
- jquery ajax回传没有值,该怎么处理
- jquery easyUI datagrid struts2有关问题
- struts2 将jsp回到到另一个jsp中
- jquery form 有关问题
- springmvc jquery ajax 提交复杂对象,415异常解决办法
- struts2 提交表单不能跳转页面有关问题!action已经执行,但是不能跳转到指定的页面
- struts2,hibernate,spring3 惯用框架的API CHM版本
- Struts2+Spring+JPA+FREEMARKER 登录程序异常
- struts2+Hibernate一个很奇怪的现象,该如何解决