ajax实现菜单联动显示信息(当选择单位的时候,动态关联出人员信息)
在jsp页面中使用onchange属性调用下面的方法:
在script中写入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | function fromid(){ var from_id = $( "#from_id" ).val(); var addurl = "&from_id=" +from_id; $.ajax({ url:<select:link page= "/YYrequireplan.do?method=fromid" />+addurl, type: "get" , dataType: "json" , success: function (html){ document.getElementById( "link_man" ).value = html[0].linkman; document.getElementById( "link_tel" ).value = html[0].tel; document.getElementById( "fax" ).value = html[0].fax; } }); } |
//后台action中调用方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public void fromid(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ String from_id = request.getParameter( "from_id" ); SqlRuturn ret; List list = null ; try { ret = Executer.getInstance().ExecSeletSQL( "select trim(linkman) as linkman,trim(tel) as tel,trim(fax1) as fax from LO_SUPPLIERFACTORY where factoryid=" +from_id); list = ret.getResultSet(); } catch (DbException e) { e.printStackTrace(); } JSONArray jsonarray = JSONArray.fromObject(list); PrintWriter out = response.getWriter(); out.print(jsonarray.toString()); out.close(); } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步