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 为实体类 希望大家能够看懂

  • 相关阅读:
    Linux eclipse 编译C++
    poj2774 Long Long Message(后缀数组or后缀自动机)
    ural 1297 Palindrome(Manacher模板题)
    bzoj 2049 Cave 洞穴勘测(LCT)
    codeforces 519E A and B and Lecture Rooms(LCA,倍增)
    hdu3830 (二分+LCA)
    codeforces 337D Book of Evil(dp)
    codeforces 22C System Administrator(构造水题)
    codeforces 144D Missile Silos(最短路)
    codeforces 505B Mr. Kitayuta's Colorful Graph(水题)
  • 原文地址:https://www.cnblogs.com/EDSON/p/AJAXWebService.html
Copyright © 2011-2022 走看看