标签:
html页面
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 <meta charset="utf-8" /> 7 <script src="scripts/jquery-1.12.4.js"></script> 8 <script> 9 $(function () { 10 $.getJSON(‘ajax_ssjl.ashx‘, { 11 pid: 0 12 }, function (msg) { 13 $.each(msg, function (index, item) { 14 $(‘#t1‘).append(‘<option value="‘ + item.AreaId + ‘">‘ + item.AreaName + ‘</option>‘); 15 $(‘#t1‘).change(); 16 }); 17 18 19 $(‘#t1‘).change(function () { 20 $.getJSON(‘ajax_ssjl.ashx‘, { 21 pid: $(‘#t1‘).val() 22 }, function (msg) { 23 $(‘#t2‘).empty(); 24 $.each(msg, function (index, item) { 25 $(‘#t2‘).append(‘<option value="‘ + item.AreaId + ‘">‘ + item.AreaName + ‘</option>‘); 26 $(‘#t2‘).change(); 27 }); 28 }); 29 }); 30 31 $(‘#t2‘).change(function () { 32 $.getJSON(‘ajax_ssjl.ashx‘, { 33 pid: $(‘#t2‘).val() 34 }, function (msg) { 35 $(‘#t3‘).empty(); 36 $.each(msg, function (index, item) { 37 $(‘#t3‘).append(‘<option value="‘ + item.AreaId + ‘">‘ + item.AreaName + ‘</option>‘); 38 $(‘#t3‘).change(); 39 }); 40 }); 41 }); 42 43 44 }); 45 }); 46 </script> 47 </head> 48 <body> 49 省<select id="t1"></select> 50 市<select id="t2"></select> 51 县<select id="t3"></select> 52 </body> 53 </html>
ashx页面
1 public void ProcessRequest(HttpContext context) 2 { 3 context.Response.ContentType = "text/plain"; 4 int pid = int.Parse(context.Request["pid"]); 5 string sql = "select * from AreaFull where AreaPId=@pid"; 6 List<NewsAreas> list = new List<NewsAreas>(); 7 #region DataTable实现方法 8 DataTable dt = SqlHelper.ExecuteDataTable(sql, new SqlParameter("@pid", pid)); 9 foreach (DataRow item in dt.Rows) 10 { 11 list.Add(new NewsAreas() 12 { 13 AreaId=Convert.ToInt32(item["AreaId"]), 14 AreaName = item["AreaName"].ToString(), 15 AreaPId = Convert.ToInt32(item["AreaPId"]) 16 }); 17 } 18 #endregion 19 20 #region SqlDataReader实现方法 21 //using (SqlDataReader reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@pid", pid))) 22 //{ 23 // if (reader.HasRows) 24 // { 25 // while (reader.Read()) 26 // { 27 // NewsAreas model = new NewsAreas(); 28 // model.AreaId = reader.GetInt32(0); 29 // model.AreaPId = reader.GetInt32(2); 30 // model.AreaName = reader.GetString(1); 31 // list.Add(model); 32 // } 33 // } 34 //} 35 36 #endregion 37 38 string json = JsonConvert.SerializeObject(list); 39 context.Response.Write(json); 40 }
标签:
原文地址:http://www.cnblogs.com/lookatyou/p/5630470.html