JSON回调传值
来源:互联网 发布:骷髅头音乐软件 编辑:程序博客网 时间:2024/05/18 03:29
json实现代码,将回调得到的值做展示
function show_etypename(){ $.getJSON("servlet/ShowEquipNameServlet?e_id="+$("#"+eid).val(),null,function call(data) { var list = data.etype; $.each(list, function(i, s) { $("#"+etype).attr("value",decodeURI(s.typeName)); }); }); }
servlet中的代码实现:
<span style="white-space:pre"></span>response.setContentType("text/json");<span style="white-space:pre"></span>request.setCharacterEncoding("utf-8");<span style="white-space:pre"></span><span style="white-space:pre"></span>String e_id=request.getParameter("e_id");<span style="white-space:pre"></span>String p_id=request.getParameter("p_id");<span style="white-space:pre"></span>String id;<span style="white-space:pre"></span>if (e_id==null) {<span style="white-space:pre"></span>id=p_id;<span style="white-space:pre"></span>} else {<span style="white-space:pre"></span>id=e_id;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>PrintWriter out = response.getWriter();<span style="white-space:pre"></span>//out.print(true);<span style="white-space:pre"></span> try{ <span style="white-space:pre"></span> EquipmentServices es=new EquipmentServices();<span style="white-space:pre"></span> EquipRegist equip = es.findEquipById(id);<span style="white-space:pre"></span> EType etype=es.findTypeById(equip.getTypeId());<span style="white-space:pre"></span> String typename=etype.getTypeName();<span style="white-space:pre"></span> <span style="white-space:pre"></span> etype.setTypeName(URLEncoder.encode(typename,"UTF-8")); <span style="white-space:pre"></span> //stu.setMoney(23); <span style="white-space:pre"></span> List<EType> list = new ArrayList<EType>(); <span style="white-space:pre"></span> list.add(etype); <span style="white-space:pre"></span> //取集合 JSONArray jsonArray = JSONArray.fromObject(list); JSONObject jsonObject = new JSONObject(); jsonObject.put("etype", jsonArray); System.out.println(jsonObject.toString()); out.write(jsonObject.toString()); <span style="white-space:pre"></span><span style="white-space:pre"></span> <span style="white-space:pre"></span> }catch(Exception e){ <span style="white-space:pre"></span> e.printStackTrace(); <span style="white-space:pre"></span> } <span style="white-space:pre"></span> <span style="white-space:pre"></span>out.flush();<span style="white-space:pre"></span>out.close();
0 0
- JSON回调传值
- Json
- JSON
- JSON
- JSON
- json
- JSON
- JSON
- json
- Json
- json
- JSON
- json
- json
- JSON
- json
- JSON
- JSON
- 幸福和分析统计分析推荐
- 利用SVM支持向量机对彩色图像进行分割并使用OpenCV进行实现
- hdu1393
- 所见过的类成员变量命名方式
- CSDN优秀博客连接,博客之星连接。
- JSON回调传值
- Synchronized
- HDU 2119 Matrix(二分图最小边覆盖)
- android中音频开发中出现的问题
- poj 1631 Bridging signals
- NSURLCache内存缓存
- Spring MVC生成验证码
- Lock
- HUD 3461 codelock 纯题意解释,不含思想