使用jquery JSON Handler实现级联效果
2010-03-30 11:19
716 查看
前台:
<script>
$(document).ready(function(){
//第一个下拉框的改变事件
$("#ddlType").change(function(){
//调用Handler时需传递一个随机参数,告诉浏览器这是一个新请求,以免调用缓存中的Handler中存储的类型,以至于其他页面中添加的新类型不能显示出来。
jQuery.getJSON("../ProductTypeHandler.ashx?w="+a,{"tid":$(this).val(),"r":Math.random()},function(date){
$("#ddlXiaoType").children().remove();
for(var i in date)
{
$("#ddlXiaoType").append("<option value='"+date[i].tid+"'>"+date[i].name+"</option>");
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:left;">
<table width="60%" style="font-size:12px;border-collapse: collapse; text-align:left" border="1px" cellpadding="0" cellspacing="0" bordercolor="#C0C0C0">
<tr><td style="text-align: center; height:20px; background-color:#CCCCCC " colspan="2" >添加产品</td></tr>
<tr>
<td style="text-align: right">类型:</td><td>
<asp:DropDownList ID="ddlType" runat="server" Width="129px">
</asp:DropDownList>
<asp:DropDownList ID="ddlXiaoType" runat="server" Width="108px">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
</form>
</body>
ProductTypeHandler.ashx中的定义:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int tid = Convert.ToInt32(context.Request.Params["tid"]);
List<cl.Model.Product_Type> newsList = new cl.BLL.gu.Product_Type().GetList(tid);//此处调用后台方法
string locationString = "";
locationString += "[";
for (int i = 0; i < newsList.Count; i++)
{
locationString += "{/"tid/":/"" + newsList[i].t_id + "/",/"name/":/"" + newsList[i].t_name + "/"}";
if (i < newsList.Count - 1)
locationString += ",";
}
locationString += "]";
context.Response.Write(locationString);//返回json字符串
}
<script>
$(document).ready(function(){
//第一个下拉框的改变事件
$("#ddlType").change(function(){
//调用Handler时需传递一个随机参数,告诉浏览器这是一个新请求,以免调用缓存中的Handler中存储的类型,以至于其他页面中添加的新类型不能显示出来。
jQuery.getJSON("../ProductTypeHandler.ashx?w="+a,{"tid":$(this).val(),"r":Math.random()},function(date){
$("#ddlXiaoType").children().remove();
for(var i in date)
{
$("#ddlXiaoType").append("<option value='"+date[i].tid+"'>"+date[i].name+"</option>");
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:left;">
<table width="60%" style="font-size:12px;border-collapse: collapse; text-align:left" border="1px" cellpadding="0" cellspacing="0" bordercolor="#C0C0C0">
<tr><td style="text-align: center; height:20px; background-color:#CCCCCC " colspan="2" >添加产品</td></tr>
<tr>
<td style="text-align: right">类型:</td><td>
<asp:DropDownList ID="ddlType" runat="server" Width="129px">
</asp:DropDownList>
<asp:DropDownList ID="ddlXiaoType" runat="server" Width="108px">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
</form>
</body>
ProductTypeHandler.ashx中的定义:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int tid = Convert.ToInt32(context.Request.Params["tid"]);
List<cl.Model.Product_Type> newsList = new cl.BLL.gu.Product_Type().GetList(tid);//此处调用后台方法
string locationString = "";
locationString += "[";
for (int i = 0; i < newsList.Count; i++)
{
locationString += "{/"tid/":/"" + newsList[i].t_id + "/",/"name/":/"" + newsList[i].t_name + "/"}";
if (i < newsList.Count - 1)
locationString += ",";
}
locationString += "]";
context.Response.Write(locationString);//返回json字符串
}
相关文章推荐
- 使用jquery和json实现系部与班级的级联
- [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果
- 使用jQuery实现select级联效果
- hibernate中关于servlet+Ajax+jquery+json+gson实现级联效果
- 使用jQuery+EasyUI实现CheckBoxTree的级联选中特效
- 使用Jquery实现顶部导航栏在页面滑动到自身所在位置之后固定在顶部的效果
- jquery+json实现的搜索加分页效果
- 使用jquery实现进度条效果
- 使用HTML5和jQuery插件Quicksand实现一个超酷的星际争霸2兵种分类展示效果
- JQuery和ASP.NET分别实现级联下拉框效果
- 使用Jquery实现图片轮播效果
- jquery调取json数据实现省市级联的方法
- 使用JQuery结合HIghcharts实现从后台获取JSON实时刷新图表
- 使用Jquery的getJSON跨域请求蘑菇街图片资源实现瀑布流
- jQuery使用fadein方法实现渐出效果实例
- jquery 使用下拉效果的实现
- jquery 使用回车键实现tab键的效果
- 使用jquery实现放大镜效果
- 使用jquery.pagination +JSON 【实现】动态无刷新分页