JSP的代码
<script type="text/javascript" src="../../jquery-1.8.0.min.js?v=<%=GlobalKey.VERSION_JS %>"></script>
<script type="text/javascript">
var app_base = "<%=request.getContextPath() %>";
</script>
<!-- 选择域下拉列表结束-->
<div class="li" >
<select id="domainID" style="width:217px;height:34px">
</select>
</div>
JS的代码
$.post(app_base + "/sys/listDomain.do",{},function(data){
/**JSON格式的DATA如何处理,请结合具体数据进行处理**/
var res_code = data.res_code;
if(res_code == 0 ){
var domains = data.body.body;
if(domains && domains.length > 0){
$.each(domains,function(idx,domainlist){/**遍历数组中数据**/
var domainname = domainlist.domainname ? domainlist.domainname : "local";
$('#domainID').append('<option value="' + domainlist.iddomain + '" id="' + domainlist.iddomain + '" name="' + domainname + '">' + domainname + '</option>');
/*往domainID的DIV追加代码*/
});
}
}
},"json");
服务器端返回的JSON数据如下:
{
"statusCode": 200,
"body": {
"head": { "error": 0 },
"body": [
{ "iddomain": 0, "domaintype": 0, "domainname": "", "domainnetworkname": "",
"domainservername": "", "domainserverport": 0, "notes": "", "status": 0
},
{ "iddomain": 9999998, "domaintype": 1, "domainname": "demo.zy.com",
"domainnetworkname": "demo.zy.com", "domainservername": "20.1.200.158",
"domainserverport": 0, "notes": "", "status": 0
},
{ "iddomain": 9999999, "domaintype": 1, "domainname": "demo.vdi.com",
"domainnetworkname": "demo.vdi.com", "domainservername": "20.1.200.109",
"domainserverport": 0, "notes": "", "status": 0
},
{ "iddomain": 10000113, "domaintype": 1, "domainname": "adtest1.com",
"domainnetworkname": "adtest1.com", "domainservername": "20.1.134.91",
"domainserverport": 389, "notes": "", "status": 0
}
]
},
"header": { "Server": "nginx/1.2.4", "Date": "Thu, 21 Mar 2013 09:07:24 GMT",
"Content-Type": "application/opzoon-v4+json", "Transfer-Encoding": "chunked",
"Connection": "keep-alive" },
"res_code": 0
}