谁能 给个 Jquery and $.get 或者 $.post 异步请求返回集合 给赋值的例子?

Orders 2010-03-12 02:54:18
谁能 给个 Jquery and $.get 或者 $.post 异步请求返回集合 给<asp:DropDownList>赋值的例子?


比如 <asp:DropDownList> 的2级联动效果,不是<select>
主要不明白 利用ascx 返回数组 然后赋值给 <asp:DropDownList> ! 汗了!
...全文
1431 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
lufeng589674 2011-08-15
  • 打赏
  • 举报
回复
JQuery AJax get取的返回的数据是页面源代码?
var t1=$("#TextBox1").val();var t2=$("#TextBox2").val();var t3=$("#TextBox3").val();

var t4=$("#TextBox4").val();var t5=$("#TextBox5").val();var t6=$("#TextBox6").val();

$.get("mail_list.aspx",{title:title,t1:t1,t2:t2,t3:t3,t4:t4,t5:t5,t6:t6},function(data){alert(data);});

为什么这里弹出的内容包括了页面的源代码?
老青菜 2010-09-21
  • 打赏
  • 举报
回复
Sandy945 佩服。 真强。。


打酱油路过。。。。
Orders 2010-03-16
  • 打赏
  • 举报
回复
Sandy945 谢呐! 呵呵!
花小也盛开 2010-03-12
  • 打赏
  • 举报
回复
[Quote=引用楼主 orders 的回复:]
谁能 给个 Jquery and $.get 或者 $.post 异步请求返回集合 给<asp:DropDownList>赋值的例子?


比如 <asp:DropDownList> 的2级联动效果,不是<select>
主要不明白 利用ascx 返回数组 然后赋值给 <asp:DropDownList> ! 汗了!
[/Quote]
网上那么多,不用提问吧。
阿非 2010-03-12
  • 打赏
  • 举报
回复
Handler.ashx 的代码贴错了,这个是


public void ProcessRequest (HttpContext context) {

context.Response.ContentType = "text/plain";

string json = string.Empty;

if (context.Request.Form["val"] == "1")
{
json = "[{\"Name\":\"北京\",\"Value\":1},{\"Name\":\"深圳\",\"Value\":2},{\"Name\":\"上海\",\"Value\":3}]";
}
else if (context.Request.Form["val"] == "2")
{
json = "[{\"Name\":\"杭州\",\"Value\":4},{\"Name\":\"苏州\",\"Value\":5},{\"Name\":\"桂林\",\"Value\":6}]";
}

context.Response.Write(json);
context.Response.End();
}
阿非 2010-03-12
  • 打赏
  • 举报
回复

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

<script>
$(function() {
$('#btn').click(function() {
$.post('Handler.ashx', { val: $("#<%=ddlMain.ClientID %>").val() }, function(data) {
var json = eval(data);
var html = '';
for (var i in json) {
html += '<option value="' + json[i].Value + '">' + json[i].Name + '</option>';
}
$("#<%=ddlSub.ClientID %>")[0].options.length = 0;
$(html).appendTo($("#<%=ddlSub.ClientID %>"));

});

});
});
</script>

</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="ddlMain" runat="server">
<asp:ListItem Text="一级城市" Value="1"></asp:ListItem>
<asp:ListItem Text="旅游城市" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlSub" runat="server">
</asp:DropDownList>
<input type="button" id='btn' value='click me' />
</form>
</body>
</html>



Handler.ashx


public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
System.Threading.Thread.Sleep(3000);
context.Response.Write(string.Format("当前时间是{0}", DateTime.Now));
context.Response.End();
}
unicode 2010-03-12
  • 打赏
  • 举报
回复
$.ajax({async: true, url: strUrl, dataType: "json", success:function(json){
for(var i = 0; i < json.length; i++){
$(you select id).options.add(new Option(json[i].text, json[i].value));
}
}});
Orders 2010-03-12
  • 打赏
  • 举报
回复
再顶!
Orders 2010-03-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sandy945 的回复:]
首先 asp:DropDownList 和 html select 是一个东西
[/Quote]
这个 知道的, 我主要是想 看 $.get or $.post 怎么返回数据集 以及 在客户端怎么遍历这个数据集!
阿非 2010-03-12
  • 打赏
  • 举报
回复
ascx 返回数组

------------------

ascx 不能自己返回,还是要构建 类似Page 的东东
huwei12345 2010-03-12
  • 打赏
  • 举报
回复
http://www.cnblogs.com/bboy/archive/2010/03/05/1679059.html
阿非 2010-03-12
  • 打赏
  • 举报
回复
首先 asp:DropDownList 和 html select 是一个东西
huwei12345 2010-03-12
  • 打赏
  • 举报
回复
返回json,遍历他,就行了。。看jquery api
Orders 2010-03-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 huwei12345 的回复:]
这玩意儿 <asp:DropDownList>,生成到页面上还是 select 的呀
[/Quote] 这个我知道,我主要是想 看 $.get or $.post 怎么返回数据集 以及 在客户端怎么遍历这个数据集!
huwei12345 2010-03-12
  • 打赏
  • 举报
回复
这玩意儿 <asp:DropDownList>,生成到页面上还是 select 的呀
Orders 2010-03-12
  • 打赏
  • 举报
回复
顶下!

62,053

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧