SpringMVC之ajax+select下拉框交互常用方式
发布时间:2020-12-15 07:11:29 所属栏目:Java 来源:网络整理
导读:! DOCTYPE html html head meta charset ="UTF-8" title Insert title here / script type ="text/javascript" src ="../js/jquery-1.8.0.min.js" / script // ajax+select三种常用交互方式 window.onload = function (){ test();} test(){ alert( " 执行 );
<!DOCTYPE html> <htmlheadmeta charset="UTF-8"title>Insert title here</> script type="text/javascript" src="../js/jquery-1.8.0.min.js"></script> //ajax+select三种常用交互方式 window.onload=function(){ test(); } test(){ alert("执行); var start = 0; size100 headNo 222221; $.ajax({ type : post,url : /ssm_pms/admin_group/list此次url改为真正需要的url data : {headNo:headNo,1)">start:start,1)">size:size },dataType : 'json(data) { loadData(data.hotelChainList); },error:(){ alert(error); } }); loadData(list){ for ( i ; i < list.length; i++) { $(#hotelNo).append(<option value=+list[i].hotels[].hotelNo>].hotelName</option>) } } /* $.ajax({ type : "post",url : "/ssm_pms/admin_group/list",//此次url改为真正需要的url data : {"headNo":headNo,"start":start,"size":size },dataType : 'json',success : function(data) { $.each(data.hotelChainList,function(index,item) { $("#hotelNo").append( //此处向select中循环绑定数据 "<option value="+item.hotels[0].hotelNo+">" + item.hotels[0].hotelName+ "</option>"); }); },}); */ */ } body> select id="hotelNo"> option>请选择酒店select> 上述三种方式,本人亲试有效,这个是比较常用的,特别是前后端交互,就拿酒店管理系统而言,部门员工等就涉及到下拉框联动,当然还有很多应用场景。 后台代码为Java代码,SpringMVC,这是web层框架,也是现在比较常用的,非常有名的。 SpringMVC代码为: /** * 查询集团下酒店店长信息及其角色信息 * @param start * size * headNo * map * @return */ @PostMapping(value="managerList",produces="application/json;charset=utf-8") @ResponseBody public String managerList(Integer start,Integer size,String headNo,Map<String,Object> map) { //角色编号为3 店长 String roleNo="3"; map.put("headNo"调用查询集团下酒店店长信息及其角色信息集合方法 List<HotelChain> hotelChainList = hotelChainService.selectManagerInfoList(map); int lines = hotelChainService.selectManagerCount(map); 调用查询集团下酒店店长信息及其角色信息总数方法 Map<String,Object> returnMap = new HashMap<String,1)">(); 根据判断结果返回不同结果集 if(lines!=0 && hotelChainList.size()!=0) { returnMap.put("hotelChainList"); returnMap.put("returnMsg","获取到数据"); }else { returnMap.put("returnCode","222221"); } return JSON.toJSONString(returnMap); } ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |