日期:2014-05-16 浏览次数:20696 次
[code=text]<script type="text/javascript">[/code]
$(document).ready(function(){
//当一级栏目选项发生变化
$('#type1').change(function(){
$('#type2').empty();
$('#type2').append("<option value='0'>---请选择二级---</option>");
//当一级栏目选项发生变化时,其对应的二级栏目也随着改变
//获取一级栏目id
var type1 = $('#type1').val();
if(type1 != 0){
$.ajax({
type: "GET",
url: "<%=basePath%>type?fid="+type1,
dataType : "json",
data : {},
success: function(data){
alert(data);
var json=eval(data);
console.log(json);
for(var i = 0, len = json.length; i < len; i++){
if(type2 == json[i].fid)
$('#type2').append("<option value='"+json[i].fid+"' selected>"+json[i].name+"</option>");
else
$('#type2').append("<option value='"+json[i].fid+"'>"+json[i].name+"</option>");
}
},
error : function (XMLHttpRequest, textStatus, errorThrows, data){
alert(data);
alert(XMLHttpRequest);
alert(textStatus);
alert(errorThrows);
}
});
}
});
});
</script>
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
this.req = request;
this.res = response;
this.session = request.getSession();
//获取父ID为fid的子id
if(req.getParameter("fid") != null){
List<String> list1 = new ArrayList<String>();
int fid = Integer.parseInt(request.getParameter("fid"));
List<Type> list2 = tdao.list(fid);
//JSONArray jsonArray = JSONArray.fromObject(list2);
/*for(Type type : list2){
list1.add(type.getId() +","+type.getName());
}*/
for(Type type : list2){
list1.add(type.getId() +":'"+type.getName()+"'");
// list1.add("type2:'"+type.getId()+"'" +"name:'"+type.getName()+"'");
}
ResponseUtil.write(response, list1);//返回值为 [4:'学院简介', 5:'组织机构', 6:'师资队伍', 7:'学科建设']
} else {
doPost(request, response);
}
}