62,053
社区成员
发帖
与我相关
我的任务
分享
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();
}
<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>
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();
}