EXT中在前台使用ajax将后台model类封装为json格式传到前台,并且解析出model中属性

前端之家收集整理的这篇文章主要介绍了EXT中在前台使用ajax将后台model类封装为json格式传到前台,并且解析出model中属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 后台
  2.  
  3. //得到报修人数据
  4. public String getBaoxiuInfo(){
  5. HttpServletRequest request = getHttpServletRequest();
  6. WarrantyService workorder = new WarrantyService();
  7. String ws_num = request.getParameter("re_num");
  8. workorder.setWs_num(ws_num); //设置编号
  9. JSONArray jsonArray = new JSONArray();
  10. JSONObject jsonData = new JSONObject();
  11. jsonArray.add(JsonUtil.beanToJson(getiWarrantyServiceService().selectBaoxiuInfo(workorder))); //将得到的model类转为Json,放入json数组中
  12. jsonData.put("BaoxiuInfo",jsonArray); //jsonData中数据格式:{"BaoxiuInfo": [{"ws_num":"abcd"}]}
  13. printHttpServletResponse(jsonData.toString());
  14. return null;
  15. }
  16.  
  17. 前台
  18.  
  19. Ext.Ajax.request({
  20. url: 'warrantyServiceAction!getBaoxiuInfo.shtml',method: 'POST',params: {re_num:recordtoedit.get("re_num")},success: function(response) {
  21. var jsonObj = Ext.util.JSON.decode(response.responseText);
  22. alert(jsonObj.BaoxiuInfo[0].ws_num); //结果为abcd
  23. }
  24. });

猜你在找的Ajax相关文章