ajax下拉查詢顯示功能

//根據專業查詢班級
function findBj(){
  if($F("zybh") != "")
    {
     url = "${pageContext.request.contextPath}/jiaowu/xjgl/zckzgl.do?method=findBjxx&zybh="+$F('zybh');
     //定義ajax對象
     var ajax = new Ajax.Request(url,
     {
      method:'post',
      onSuccess:onBj
     }
     );

    }else{
     while($("bjbh").length>1){
      $("bjbh").remove(1);
     }      
  } 
}

//顯示班級    
function onBj(response){ 

 while($("bjbh").length > 1){
     $("bjbh").remove(1);
   }
 var bjstr = response.responseText.split(",");

 for(var i =0;i<bjstr.length;i++)
    {
    if(bjstr[i] != "")
     {
      var bj = bjstr[i].split("#");
      $("bjbh").options[$("bjbh").length] = new Option(bj[1],bj[0]);
     }
 }     
}

/**
  * 根據專業編號查詢班級信息
  *
  * @param mapping
  * @param actionForm
  * @param request
  * @return ActionForward
  */
 public ActionForward findBjxx(ActionMapping mapping, ActionForm actionForm,
   HttpServletRequest request, HttpServletResponse response) {
  String zybh = request.getParameter("zybh");
  String rxnf=request.getParameter("rxnf");
  String bjxx = this.getIXszcglService().findBjByZy(zybh,rxnf);
  try {
   response.setCharacterEncoding("utf-8");
   response.getWriter().print(bjxx);
  } catch (Exception e) {
   e.printStackTrace();
  }
  return null;
 }

/**
  * 根據專業查詢班級
  *
  * @param zybh
  * @return
  */
 
 public String findBjByZy(String zybh,String rxnf) {
  List args = new ArrayList();
  args.add(zybh);
  
  String hql = "from Xs0206 bj where bj.zzdBjlbb.dm='1' and bj.jx01.zybh = ? and bj.zzdBjlbb.dm='1' and bj.bjjc is not null";
  if(!StringUtils.nullOrBlank(rxnf)){
   hql+=" and bj.rxnf=?";
   args.add(rxnf);
  }
  List bj = this.singleGenericHibernateDAO.find(hql, args);
  StringBuffer bjxx = new StringBuffer();
  Iterator iterator = bj.iterator();
  while (iterator.hasNext()) {
   Xs0206 xs0206 = (Xs0206) iterator.next();
   bjxx.append(",");
   bjxx.append(xs0206.getBjbh() + "#" + xs0206.getBjjc());
  }
  return bjxx.toString();
 }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章