日期:2014-05-16  浏览次数:20356 次

json数据传输,客户端下拉框循环输出
PrintWriter out;
try {
out = response.getWriter();
List<ProviderSysCode> list = prospectusService.getbranchIdToProvidername(user.getBranchId());
String providerList = CommonUtil.getJSONString(list);
out.print(providerList);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
=============================================
从后台传回的json数据(providerList)
----------------------------------
[{"productcode":"","productname":"","providerabbr":"光大永明","providercode":"GDYM","providerid":"PRO0000000000033","providername":""},
{"productcode":"","productname":"","providerabbr":"新华人寿","providercode":"XHRS","providerid":"PRO0000000000027","providername":""},
{"productcode":"","productname":"","providerabbr":"昆仑健康(产险)","providercode":"KLJK_CX","providerid":"PRO0000000000835","providername":""}]
================================================
<script type="text/javascript">
$(document).ready(function() {
var requestUrl = "${path}/routine/prospectus/index/providername";
// 取供应商
$.ajax( {
type : "post",//默认为get  
dataType : "json",
url : requestUrl,
success : function(providerList) {
// 供应商
var selStr = "";
for(var index in providerList){
for(var key in providerList[index]){
if(key == 'providername'){
if(providerList[index][key] == "${providername}"){
selStr += "<option value='"
           + providerList[index][key]
   + "' selected='selected'"
   +" >"
   + providerList[index][key]
           + "</option>";
}else{
selStr += "<option value='"
           + providerList[index][key]
   +"' >"
   + providerList[index][key]
           + "</option>";
}
//alert(providerList[index]['providercode']+":"+providerList[index][key]);
}
}
}
$("#provides").html(selStr);
  }
});

}); 
</script>

--------html-------
<th>
供应商:
</th>
<td>
<select class="input-txt" id="provides" style="width: 124px;" name="provides">

</select>
</td>