ajax. net +jquery does not refresh the instance code of three level linkage

  • 2020-06-12 08:50:12
  • OfStack


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Jquery1.7.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "post",
                contentType: "application/json",
                url: "WebService1.asmx/loadprovince",
                data: "{}",
                success: function (result) {
                    var ping;
                    for (var i = 0; i < result.d.length; i++) {
                        ping += "<option value=" + result.d[i].provinceID + ">";
                        ping += result.d[i].provincename;
                        ping += "</option>";
                    }
                    $('#Select1').append(ping);
    
                }
    
            })
            $('#Select1').change(function () {
                // The first 2 Remember to empty the city and county at the next election 
                $('#Select2 option:gt(0)').remove();
                $('#Select3 option:gt(0)').remove();
                // Bind in save change event 1 Make a list (to lose the province id ) 
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/loadcity",
                    data: "{fatherid:'" + $('#Select1 option:selected').val() + "'}",
                    success: function (result) {
                        var str2;
                        for (var i = 0; i < result.d.length; i++) {
                            str2 += "<option value=" + result.d[i].cityID + ">";
                            str2 += result.d[i].cityname;
                            str2 += "</option>";
                        }
                        $('#Select2').append(str2);
                    }
                })
            })
            $('#Select2').change(function () {
                $('#Select3 option:gt(0)').remove();
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/loadarea",
                    data: "{fatherid:'" + $('#Select2 option:selected').val() + "'}",
                    success: function (result) {
                        var str3;
                        for (var i = 0; i < result.d.length; i++) {
                            str3 += "<option value=" + result.d.areaID + ">";
                            str3 += result.d[i].areaname;
                            str3 += result.d[i].father;

                        }
                        $('#Select3').append(str3);
                    }
                })
            })
        })

    </script>
</head>
<body>
    Save: 
    <select id="Select1">
        <option>-- Please select a --</option>
    </select>
     City: 
    <select id="Select2">
        <option>-- Please select a --</option>
    </select>
     County: 
    <select id="Select3">
        <option>-- Please select a --</option>
    </select>
</body>
</html>

webservice:


 [WebMethod]// Load the province 
        public List<Model.province> loadprovince()// Why use list Because it's impossible to get the previous value here 1 The instances are multiple model Instance, 1 An example of that is 1 This is done to prevent field errors 
        {
            BLL.province bp = new BLL.province();
            List<Model.province> list=bp.getlistModel();
            return list;
        }
        [WebMethod]// Loading, 
        public List<Model.city> loadcity(string fatherid) 
        {
            BLL.city bc = new BLL.city();
            List<Model.city> list = bc.getlistmodel(fatherid);
            return list;
        }
        [WebMethod]// Load the county 
        public List<Model.area> loadarea(string fatherid)
        {
            BLL.area ba = new BLL.area();
            List<Model.area> list = ba.getlistmodel(fatherid);
            return list;

        }
    }
}

DAL--area


public System.Collections.Generic.List<Model.area> getlistmodel(string fatherid)
        {
            System.Collections.Generic.List<Model.area> list = new System.Collections.Generic.List<Model.area>();
            DataTable dt = GetList("father=" + fatherid + "").Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                Model.area ma = new Model.area();
                ma.areaID = row["areaID"].ToString();
                ma.areaname = row["areaname"].ToString();
                ma.father = row["father"].ToString();
                list.Add(ma);
            }
            return list;
        }

Dal--city


 public System.Collections.Generic.List<Model.area> getlistmodel(string fatherid)
        {
            System.Collections.Generic.List<Model.area> list = new System.Collections.Generic.List<Model.area>();
            DataTable dt = GetList("father=" + fatherid + "").Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                Model.area ma = new Model.area();
                ma.areaID = row["areaID"].ToString();
                ma.areaname = row["areaname"].ToString();
                ma.father = row["father"].ToString();
                list.Add(ma);
            }
            return list;
        }
    }

DAL-provience


public System.Collections.Generic.List<Model.province> getlistModel()
        {
            // The content to be looked up is returned as an instance 
            // So what we're going to do here is we're going to build list And will be list with model The instance is filled, and model Want to use 1 Method to lose data and add to model In the 
          // build list The instance 
            System.Collections.Generic.List<Model.province> list = new System.Collections.Generic.List<Model.province>();
            // You already have a method that loses data so you don't have to write it yourself by calling it Getlist Methods to manipulate the database to get data 
            DataTable dt = GetList("").Tables[0];
            // Once you get the data, you need to add the data to it model Instance of the 

            foreach (DataRow row in dt.Rows)
            {
                // every 1 Each row is an instance so I'm going to put model I put it in the loop 
                Model.province mp = new Model.province();
                mp.provinceID = row["provinceID"].ToString();
                mp.provincename = row["provincename"].ToString();
                list.Add(mp);// Don't add the 1 I'm going to put all the instances in list In the 
            }
            return list;
 
        }


Related articles: