struts2 ajax 二級菜單級聯

//頁面code
function replyMessage() {
var cityCode = $("#code").val();
        if (cityCode != null && cityCode != "") {
        $("#hallname").children().eq(0).siblings().remove();
            $.ajax({   
                url:'${appPath}/ht/hd!getBhnameByCityCode.action?cityCode='+cityCode+'&hallname=<%=request.getAttribute("hallname") %>',   
                type:'post',   
                date:{},
                async:false,   
                success:function(sb) { 
$("#hallname").append(sb);
document.getElementById("hall").innerHTML=document.getElementById("hall").innerHTML.replace(/jQuery[^=]*="6"/,"");
},  
                error:function() { 
                    alert("error");   
                }   
            });   
        }
    }




//後臺code
PrintWriter writer = null;
StringBuffer sb = new StringBuffer();
String cityCode = request.getParameter("cityCode");
String hallname = "";
if(request.getParameter("hallname") != null){
hallname = request.getParameter("hallname");
}
if(cityCode != null && !"".equals(cityCode)){
businessHall=(List<BusinessHall>) service.getEntities("from BusinessHall h where h.citycode='"+cityCode+"'", null);
for(BusinessHall businesshall : businessHall){
if(hallname.equals(String.valueOf(businesshall.getBhseq()))){
sb.append("<option selected='selected' value='" + businesshall.getBhseq() + "'>" + businesshall.getBhname() + "</option>");
}else{
sb.append("<option value='" + businesshall.getBhseq() + "'>" + businesshall.getBhname() + "</option>");
}
}
}
try {
    response.setContentType("text/html;charset=gbk");
    response.setHeader("Cache-Control", "no-cache");
    writer = response.getWriter();
    writer.write(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}finally{
writer.close();
}
return null;
}

發佈了4 篇原創文章 · 獲贊 7 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章