Sql | |
$(document).ready(function(){ $(".dept").bind("click", function () { var self = this; var open = $(self).attr("open"); if (open=="false") { $(self).attr("open", "true"); } $.ajax({ type: "post", data: { data: JSON.stringify( {Description:$(this).attr("desc")}) }, url: "GetDeptName.ashx", success: function (data) { if (data != null || data !== "") { if (open=="false") { $(self).children(".dept").remove(); return false; } var entitys = JSON.parse(data); $.each(entitys.prod, function (index, element) { var ul = $("<ul></ul>"); var li = "<li><span class=‘dept‘ open=‘false‘ desc=‘" + element.Description + "‘>" + element.Name + "</span></li>"; ul.append(li); $(self).after(ul); }); } } }); }); });
c#代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Script.Serialization; namespace Maticsoft.Web.Product { /// <summary> /// GetDeptName 的摘要说明 /// </summary> public class GetDeptName : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; JavaScriptSerializer jss = new JavaScriptSerializer(); string entity = context.Request["data"]; Model.Products model= jss.Deserialize<Model.Products>(entity); List<Model.Products> prod = new BLL.Products().GetModelList(string.Format(" Catagory={0}",model.Description)); if (prod!=null&&prod.Count()>0) { context.Response.Write(jss.Serialize(new {prod= prod})); return; } context.Response.Write(string.Empty); } public bool IsReusable { get { return false; } } } }
原文:http://www.cnblogs.com/oran/p/4356476.html