JSON回调传值

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值