前台:
选择地区:<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="C_Title" DataValueField="C_ID"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" DataTextField="C_Title" DataValueField="C_ID"> </asp:DropDownList>
$(function(){ $("#DropDownList1").change(function(){ $.ajax({ url: '/UI/DBBase/City.ashx', data:{id:$(this).val()}, type: 'get', cache:false, dataType: "json",/*这句可用可不用,没有影响*/ contentType: "application/json; charset=utf-8", success: function(result){ $("#DropDownList2 option").remove(); $.each( result, function (i, o) { $("#DropDownList2").append("<option value='"+o.C_ID+"'>"+o.C_Title+"</option>"); }); }, error: function(){alert('市区加载错误');} }); }) })
ashx:
<%@ WebHandler Language="C#" Class="City" %> using System; using System.Web; using Web.Dal; using System.Data; public class City : IHttpHandler { public void ProcessRequest (HttpContext context) { int parID = Convert.ToInt32(context.Request.QueryString["id"]); DataTable dt = new CityServer().Get(parID); context.Response.Write(JSONHelper.DataTableToJSON(dt)); } public bool IsReusable { get { return false; } } }
- 本文标题: JQuery 二级联动菜单加载
- 文章分类:【JQuery/JavaScript】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.