首页 > Web开发 > 详细

JQuery 1.3.2联动获取部门

时间:2015-03-22 00:09:55      阅读:391      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!