码迷,mamicode.com
首页 > Web开发 > 详细

JQuery 1.3.2联动获取部门

时间:2015-03-22 00:10:23      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

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

  

JQuery 1.3.2联动获取部门

标签:

原文地址:http://www.cnblogs.com/oran/p/4356476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!