zoukankan      html  css  js  c++  java
  • AJAX 和WebService 现实多个DropdownList联动

    1:前台jquery代码

            //根据部门 获取员工姓名
            function GetEmployeeName() {
                var gid = $("# MdDepartment_ParentID");
                var gpid = $("#HrEmployee_EmployeeName");
                $("#HrEmployee_EmployeeName option").remove(); // 先删除所有项,以便重新加载 
                gpid.append("<option value=''>--- 请选择 ---</option>"); //默认项
                $.ajax({
                    type: "Post",
                    url: "Edit.aspx/getEmployeeName",
                    data: "{'DepartmentID':'" + gid.val() + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var arrayChar = data.d;
                        for (var index in arrayChar) {
                            if (typeof arrayChar[index] != 'undefined' && typeof arrayChar[index] != 'function') {
                                var info = arrayChar[index];
                                gpid.append($("<option></option>").val(info.ID).html(info.EmployeeName));
                            }
                        }
                    },
                    error: function (err) {
                    }
                });
            }

            //获取员工工号
            function GetWorkNumInfo() {

                var gid = $("#HrEmployee_EmployeeName");
                var ms = $("#HrEmployee_WorkNo");
                $.ajax({
                    type: "Post",
                    url: "Edit.aspx/GetWorkNumInfo",
                    data: "{'ID':'" + gid.val() + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var arrayObj = data.d.toString().split(",");
                        ms.val(arrayObj[0]);
                    },
                    error: function (err) {
                        //alert(err);
                    }
                });
                      }

    2:后台代码.cs

     [System.Web.Services.WebMethod]
        public static List<string> GetWorkNumInfo(string ID)
        {
            List<string> list = new List<string>();
            HrEmployee bll = new HrEmployee();
            HrEmployeeInfo info = bll.GetModel(ID);
            if (info != null)
            {
                list.Add(info.WorkNo);
            }
            return list;
        }

        [System.Web.Services.WebMethod]
        public static List<HrEmployeeInfo> getEmployeeName(string DepartmentID)
        {
            HrEmployee bll = new HrEmployee();
            List<DBParameter> dbParameters = new List<DBParameter>();
            dbParameters.Add(new DBParameter("@DepartmentID", DepartmentID));
            List<HrEmployeeInfo> list = bll.GetList("", "DepartmentID=@DepartmentID", "", dbParameters);
            return list;
        }

    注:HrEmployeeInfo 为实体类 希望大家能够看懂

  • 相关阅读:
    离线存储
    创业公司 加入
    console 代理
    HTTP 协议中 Vary 的一些研究
    reactNative 的一些学习
    srcset 图片自适应
    一些不错的文章分享
    前端网站大全
    c# 捕捉键盘按键
    SQL 中With as 的用法
  • 原文地址:https://www.cnblogs.com/EDSON/p/AJAXWebService.html
Copyright © 2011-2022 走看看