?
?1、action 片段
class="java">public Map responseJson; public Map getResponseJson() { return responseJson; } public void setResponseJson(Map responseJson) { this.responseJson = responseJson; }
Map<String, Object> map = new HashMap<String, Object>(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> m = new HashMap<String, Object>(); m.put("m0001",m0005.getM0001()); m.put("m0002",m0005.getM0002()); list.add(m); map.put("status", 1); map.put("M0005List", list); this.setResponseJson(map);
?
<package name="shopManagerJson" extends="json-default" namespace="/shopManagerJson"> <action name="*" class="com.mall.shop.action.ShopAction" method="{1}"> <result type="json"> <!-- 这里指定将被Struts2序列化的属性,该属性在action中必须有对应的getter方法 --> <param name="root">responseJson</param> </result> </action> </package>
?
?
3、js
$.post(postUrl,{gid:goodsId,num:goodsNum,sid:shopid},function(data){ if(data.status){ tdTemp.empty(); $.each(data.M0005List,function(i, item){ tdTemp.append('<td bgcolor="#ffffff" align="center" style="width:250px;" valign="middle"><a href="<%=basePath%>goodsManager/toFindGoodsPage.do?id='+item.m0003+'" target="_blank"><img style="width:50px; height:50px;" src="<%=basePath%>photo/'+item.m0010+'" border="0"><br>'+item.m0007+'</a> </td>'); tdTemp.append('<input name="goodsId" type="hidden" value="'+item.m0003+'"><input name="sid" type="hidden" value="'+item.m0001+'">'); tdTemp.append('<td bgcolor="#ffffff" align="center">'+item.m0004+' <br></td>'); tdTemp.append('<td align="center" bgcolor="#ffffff"><span class="price">'+item.m0008.toFixed(1)+'</span></td>'); tdTemp.append('<td align="center" bgcolor="#ffffff"><input class="min" name="" type="button" value="-"> <input type="text" name="" id="goods_number" readonly="readonly" value="'+item.m0005+'" size="4" class="text_box" style="text-align:center "> <input class="add" name="" type="button" value="+"> </td>'); tdTemp.append('<td align="center" bgcolor="#ffffff"><span class="priceSmallTotal">'+item.m0006.toFixed(1)+'</span></td>'); tdTemp.append('<td align="center" bgcolor="#ffffff"><a href="javascript:if (confirm(\'您确实要把该商品移出购物车吗?\')) location.href=\'<%=basePath%>shopManager/delM0005.do?id='+item.m0001+'\';">删除</a></td>'); }); }else{ alert('获取失败!'); window.location.reload(); } },'json');
?