【发布时间】:2016-04-21 15:41:47
【问题描述】:
我正在尝试根据从 Web 服务获取的 JSON 数组填充 dropDownList。
这是我得到的 Json 数组的示例:
[{"id":1,"name":"AJ Shaw"},{"id":2,"name":"Jay Black"}]
这是我用来尝试加载 dropDownList 的 javascript
function load_level1() {
$.ajax({
url: '<%=ResolveUrl("/facility/getTaxLevel1_LOV")%>',
contentType: "application/json; charset=utf-8",
dataType: "json",
method: "GET",
success: function (Result) {
$.each(Result, function(key, value) {
$("#level1").append($("<option></option>").val
(value).html(value));
});
},
error: function (Result) {
alert("Error");
},
failure: function (Result) {
alert(response.responseText);
}
});
}
这是我的 dropDownList 对象:
<asp:DropDownList ID="level1" runat="server" AppendDataBoundItems="true" ><asp:ListItem Selected="True" Value="Select Level 1" ></asp:ListItem></asp:DropDownList>
我只想用 Id 和名称填充 dropDownList。不可能那么难,但我迷路了。有什么建议吗?
【问题讨论】:
-
<asp:DrownDownList>是一个服务器端组件。是否可以在服务器上加载项目,而不是在客户端(通过 AJAX)?
标签: c# jquery asp.net json ajax