JQuery 1.3.2联动获取部门

2018-06-18 02:52:47来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:日志管理-Log4net

下一篇:.NET零基础入门之02:源码控制管理器的使用