ajax

 1  $("#dlProvince").change(function () {
 2              var id = document.getElementById("dlProvince").value;
 3              Load("SCity", id);
 4          });
 5          $("#SCity").change(function () {
 6              var sid = document.getElementById("SCity").value;
 7              Load("SSHI", sid);
 8          });
 9 
10          function Load(obj, pid) {
11              var url = "/WebUI/Admin/Benefit/Area.ashx?pid=" + pid + "&obj=" + obj;
12              $.get(url, null, function (data) {
13                  var jsonlist = eval(data);
14                  for (var i = 0; i < jsonlist.length; i++) {
15                      var op = new Option(jsonlist[i].Name, jsonlist[i].Id);
16                      document.getElementById(obj).options.add(op);
17                  }
18              });
19              //var xmlhttp = new XMLHttpRequest();
20              //if (xmlhttp == null) {
21              //    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
22              //}
23              
24              //alert(url);
25              //xmlhttp.open("GET", url, true);
26              //xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
27              //xmlhttp.onreadystatechange = function () {
28              //    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
29              //        document.getElementById(obj).innerHTML = "<option value='0'>-请选择-</option>";
30              //        var jsonlist = eval(xmlhttp.responseText);
31                     
32              //        for (var i = 0; i < jsonlist.length; i++) {
33              //            var op = new Option(jsonlist[i].Name, jsonlist[i].Id);
34              //            document.getElementById(obj).options.add(op);
35              //        }
36              //    }
37              //}
38              //xmlhttp.send(null);
39          }
40 
41 
42 
43 //一般处理程序
44  public void ProcessRequest(HttpContext context)
45         {
46             context.Response.ContentType = "text/plain";
47             string obj = context.Request.QueryString["obj"];
48             string id = context.Request.QueryString["pid"];
49             if (obj == "SCity")
50             {
51                 SysLocation Location = new SysLocation();
52                 Location.AddCondition("Depth", 3);
53                 Location.AddCondition("Pid", id);
54                 IList<SysLocation> listCity = BDAContext.GetObject<ISysLocationBLL>().QueryPageList(Location, 1, int.MaxValue);
55                 string json = JsonConvert.SerializeObject(listCity);
56                 context.Response.Write(json);
57             }
58             else
59             {
60 
61                 SysLocation obje = new SysLocation();
62                 obje.AddCondition("Depth", 4);
63                 obje.AddCondition("Pid", id);
64                 IList<SysLocation> listDistrict = BDAContext.GetObject<ISysLocationBLL>().QueryPageList(obje, 1, int.MaxValue);
65                 string json = JsonConvert.SerializeObject(listDistrict);
66                 context.Response.Write(json);
67             }
68 
69 
70         }
//前台
             <Bda:SortableGridRow>
                                    <HeaderTemplate Width="150px">
                                地区<span style="color: #FF0000">*</span>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                   
                   <asp:DropDownList ID="dlProvince" runat="server" AutoPostBack="true" ClientIDMode="static" Height="25px" Width="30%"></asp:DropDownList>&nbsp;
                                        <select id="SCity"  ClientIDMode="static" runat="server" ><option value='0'>-请选择-</option></select>
                                        <select id="SSHI"  ClientIDMode="static" runat="server" ><option value='0'>-请选择-</option></select>
                   <%--<asp:DropDownList ID="dlCity" runat="server" AutoPostBack="true" ClientIDMode="static" Height="25px"  Width="30%"></asp:DropDownList>--%>&nbsp;
                    <%--<asp:DropDownList ID="ddlcounty" runat="server" Height="25px"  Width="30%"></asp:DropDownList>--%>&nbsp;
                  
                                <%--<asp:TextBox ID="Location" runat="server" CssClass="TextStyle validate[required,minSize[2]] text-input" Width="90%" MaxLength="20"></asp:TextBox>--%>
                                    </ItemTemplate>
                                </Bda:SortableGridRow>

 

posted @ 2013-08-29 19:06  yufeiyunsui  阅读(172)  评论(0编辑  收藏  举报