jquery json实现二级动态联动
- 以下为代码!需要导入json架包
- function getCity1(){
- var unitid = document.getElementById('addformunitid').value;
- $.getJSON("../unit/getcity.do?unitid="+unitid, "", function(response){
- //$ ("#departmentid").show();//将隐藏的select显示出来
- $ ("#adddepartmentid option").remove();//将select中的信息清空
- $ ("#adddepartmentid").attr("disabled",false);
- //alert(response);
- $.each(response,function(i){
- //encodeURI(response[i]);
- //encodeURI(fileName)
- //将后台传回的信息打印到页面中
- $ ("#adddepartmentid").append ("<option value="+response[i].id+">"+ response[i].departmentname +"</option>");
- });
- });
- }
- <tr>
- <td class="td_title">所属单位<em>*</em></td>
- <td>
- <select name="eform.unitid" id="addformunitid" onChange="getCity1();">
- <option value="0">请选择</option>
- <#list unitList as ul>
- <option value="${ul.id}">${ul.unitname}</option>
- </#list>
- </select>
- </td>
- <td class="td_title">部门<em>*</em></td>
- <td>
- <select name="eform.departmentid" id="adddepartmentid" disabled="disabled">
- <option value=" ">请选择</option>
- </select>
- </td>
- <td class="td_title">职位<em>*</em></td>
- <td>
- <select name="eform.positionid">
- <option value=" ">请选择-</option>
- <#list positionList as pl>
- <option value="${pl.id}">${pl.positionname}</option>
- </#list>
- </select>
- </td>
- </tr>
- <!-- 单位,部门二级联动 -->
- <package name="unit" extends="webwork-default" namespace="/unit">
- <action name="getcity" class="com.hnbus.action.unit.EmployeeJsonAction" method="getcity" >
- <interceptor-ref name="defaultStack"/>
- </action>
- </package>
- /*
- *文件名:EmployeeJsonAction.java
- *描 述:二级联动action
- *版 权:********有限公司 Copyright (c) 2008-2013,All Rights Reserved.
- *创建者:向洁
- *修改者:向洁
- */
- package com.hnbus.action.unit;
- import java.io.PrintWriter;
- import java.net.URLDecoder;
- import java.util.List;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import net.sf.json.JSONArray;
- import org.apache.log4j.Logger;
- import org.eps.action.BaseAction;
- import com.hnbus.model.Department;
- import com.hnbus.model.Employee;
- import com.hnbus.service.unit.EmployeeService;
- import com.opensymphony.webwork.ServletActionContext;
- /**
- * @Description (二级联动action)
- * @author 向洁
- * @version JOHOM V1.0
- * @Date 2013-8-4-下午10:54:05
- * @see
- */
- public class EmployeeJsonAction extends BaseAction{
- private static final Logger logger = Logger.getLogger(EmployeeAction.class);
- @Resource
- private EmployeeService employeeService;
- private EmployeeForm1 eform;
- private String unitid;
- public String getcity() throws Exception {
- logger.info("选择单位ID");
- //获取前台传来的值
- String unitid = this.getRequest().getParameter("unitid");
- HttpServletResponse response = ServletActionContext.getResponse();
- /*设置字符集为'UTF-8'*/
- response.setContentType("text/plain;charset=utf-8");
- List<Department> department = employeeService.findSameDepartmentlist(unitid);
- ServletActionContext.getRequest().getSession().setAttribute("department",department);
- //将list转换成JSON对象
- JSONArray jr = JSONArray.fromObject(department);
- PrintWriter out = this.getResponse().getWriter();
- //将JSON对象转换成String类型传入前台
- String jsonUser = jr.toString();
- out.print(jsonUser);
- out.flush();
- out.close();
- return null;
- }
- /**
- * 变量:employeeService
- * @return 变量:employeeService
- */
- public EmployeeService getEmployeeService() {
- return employeeService;
- }
- /**
- * 变量:eform
- * @return 变量:eform
- */
- public EmployeeForm1 getEform() {
- return eform;
- }
- /**
- * 变量:eform
- * @param eform (Set the variable:eform)
- */
- public void setEform(EmployeeForm1 eform) {
- this.eform = eform;
- }
- /**
- * 变量:employeeService
- * @param employeeService (Set the variable:employeeService)
- */
- public void setEmployeeService(EmployeeService employeeService) {
- this.employeeService = employeeService;
- }
- /**
- * 变量:logger
- * @return 变量:logger
- */
- public static Logger getLogger() {
- return logger;
- }
- /**
- * 变量:unitid
- * @return 变量:unitid
- */
- public String getUnitid() {
- return unitid;
- }
- /**
- * 变量:unitid
- * @param unitid (Set the variable:unitid)
- */
- public void setUnitid(String unitid) {
- this.unitid = unitid;
- }
- }
- class EmployeeForm1 extends Employee{}
jquery json实现二级动态联动的更多相关文章
- Ajax和JSON完成二级菜单联动的功能
首先需要找好JSON的包哦: 链接:http://pan.baidu.com/s/1jH6gN46 密码:lbh1 1:首先创建一个前台页面,比如secondMenu.jsp,源码如下所示: < ...
- jQuery + json 实现省市区三级联动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js 省份城市二级动态联动的例子
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 《DWZ笔记一》<select>动态联动菜单
联动菜单,即组合框Combo box,在DWZ文档中对组合框combox的是这样描述的: 在传统的select 用class 定义:class=”combox”, html 扩展:保留原有属性name ...
- Json 基于jQuery+JSON的省市联动效果
helloweba.com 作者:月光光 时间:2012-09-12 21:57 标签: jQuery JSON Ajax 省市联动 省市区联动下拉效果在WEB中应用非常广泛,尤其在一些 ...
- 份-城市,基于jQuery的AJAX二级联动,用Struts2整合AJAX【非数据库版】
package loaderman.provincecity; import java.io.IOException; import java.util.LinkedHashSet; import j ...
- JavaScript(jquery)实现二级菜单联动
为什么写这篇随笔? 二级菜单的联动一直是我心中一块石头,犹记得大一的时候只会用一点的Dreamweaver,当时做二级菜单难受啊,啥都不会,网上找了些资料,也看不懂别人的代码更别说用起来了 前些日子. ...
- 省市联动_简单的Demo,适用于各种二级菜单联动
最近搞了一个功能,是查询页面需要用到二级菜单联动,获取到选中的属性value传入到后台. 平常都是用AJAX或者JQuery ,通过XML或者JSON的方式,这样的话需要调用数据库,像典型得到省市联动 ...
- JQuery+Ajax实战三级下拉列表联动(八)
本片文章为练习,项目中不会这样写: 一:涉及到的知识点: jQuery Dom操作 jQuery Ajax操作 ASP.net中的json操作 二:用了自动代码生成器 1.Dal层的代码: publi ...
随机推荐
- customPage.class.php可添加js事件的分页类
用于ajax动态加载数据的分页类,分页事件可以动态添加,去除了a链接中的href地址. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- thinkphp中导入和使用阿里云OSSsdk
照做绝对行,在ThinkPHP中,第三方库都放在ThinkPHP/Library/Vendor/路径下. 1.下载OSS PHP SDK:https://help.aliyun.com/documen ...
- ubuntu16.04 安装symfony3.3.11 碰到的问题:extension dom is required | oops an error occurred 500
问题1:Uncaught exception 'RuntimeException' with message 'Extension DOM is required' 解决:sudo apt-get i ...
- 【原创】MySQL复制slave服务器死锁案例
MySQL复制刚刚触发了一个bug,该bug的触发条件是slave上Xtrabackup备份的时候执行flushs tables with read lock和show slave status有可能 ...
- Android消息总线的演进之路:用LiveDataBus替代RxBus、EventBus
背景 对于Android系统来说,消息传递是最基本的组件,每一个App内的不同页面,不同组件都在进行消息传递.消息传递既可以用于Android四大组件之间的通信,也可用于异步线程和主线程之间的通信.对 ...
- JavaQuery操作对象
1.jQuery操作的分类 <!DOCTYPE html> <html> <head lang="en"> <meta cha ...
- SQL注入实验
看到他们黑站感觉很有意思的样子,于是我也玩了一下午,虽然都是些狠狠狠简单的东西,不过还是记录下来啦. 虽然和我现在做的没啥关系,不过,,,挺好 浏览器的“工具”——“internet选项”——“高级” ...
- 深入理解ajax系列第六篇
前面的话 每个HTTP请求和响应都会带有相应的头部信息,其中有的对开发人员有用.XHR对象提供了操作头部信息的方法.本文将详细介绍HTTP的头部信息 默认信息 默认情况下,在发送XHR请求的同时,还会 ...
- Centos 安装 Wireshark
Wireshark是一款数据包识别软件,应用很广泛. yum install wireshark yum install wireshark-gnome
- luoguP4696 [CEOI2011]Matching KMP+树状数组
可以非常轻易的将题意转化为有多少子串满足排名相同 注意到$KMP$算法只会在当前字符串的某尾添加和删除字符 因此,如果添加和删除后面的字符对于前面的字符没有影响时,我们可以用$KMP$来模糊匹配 对于 ...