Ajax+JSon 직렬 메뉴 구현 코드

1859 단어 Json연속 메뉴
첫 번 째 드 롭 다운 상자:
 
<select id="select" name="rawfoodBasic.category" onchange="doChange(this.value);">
//
</select>
두 번 째 드 롭 다운 상자:
 
<select id="subSelect" name="rawfoodBasic.absorb" onchange="javascript:alert(this.value);" > // 3
<option value="0">-- -- </option>
</select>
js 코드:
 
<script type="text/javascript">
$.ajaxSetup({
cache:false
}); // ajax
function doChange(obj){
var url = '<c:url value="/nutrition/getSubDictDataToJsonByCategory.action"/>'+"?rawfood.category="+obj;// action,action
$.getJSON(url,function(json){
var seleOjb=document.getElementById("subSelect");
for(var k=0;k<seleOjb.options.length;k++){
seleOjb.options.remove(k); // ,
}
$.each(json.subCategoryDictList,function(index,subDictData){
var optionj=document.createElement("option"); //
optionj.value = subDictData.id;
//alert(subDictData.id);
optionj.text=subDictData.name;
seleOjb.add(optionj);
});
});
}
</script>
 
<action name="getSubDictDataToJsonByCategory" class="rawfoodAction" method="getSubDictDataToJsonByCategory">
<result name="success" type="json">
<param name="includeProperties"> //
^subCategoryDictList\[\d+\]\.id,
^subCategoryDictList\[\d+\]\.name
</param>
</result>
</action>

좋은 웹페이지 즐겨찾기