JQuery 1.3.2联动获取部门

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;
            }
        }
    }
}

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。