在jquery ajax中,我从数据库中获取值并需要在下拉菜单中显示。首先我传递id并获取关卡。与tat级id和名称,我再次获取与选定的级别相关的值,并显示在从返回jquery ajax对象的下拉列表中。下拉值从返回jquery ajax成功
不插入结果在下拉(测试功能)
function Level(Id) {
$.ajax({
url: 'GetLevel' + '/?Id=' + Id,
type: "POST",
dataType: "json",
contentType: 'application/json',
success: function (result) {
testing(value.Value);
},
complete: function() { },
error: ServiceFailed// When Service call fails
});
}
function testing(LevelId) {
result = getDropdownValues();
$('#drp >option').remove();
for (var i = result.length; i--;) {
$.each(result, function (key, value) {
$("#drp").append($("<option></option>").val(value.Key).html(value.Value));
});
//not inserting the result in drop down
//from the return object.
}
}
}
function getDropdownValues (LevelId, selectedLevel) {
var passVal = null;
$.ajax({
url: 'GetValues' + '/?selectedLevel=' + selectedLevel + '&LevelId=' + LevelId,
type: "POST",
dataType: "json",
contentType: 'application/json',
async: false,
success: function (result) {
passVal = result;
},
complete: function() { },
error: ServiceFailed// When Service call fails
});
return passVal;
}
,并使用C#类
public class Level
{
public int Id { get; set; }
public string Name { get; set; }
public List<ListEntity> Value { get; set; }
}
...你的问题是? – Tomalak
不生成下拉列表。 – user930453
你能编辑你的问题来说明问题出在哪里吗?您是否从服务器获取任何数据?或者你只是不确定如何将这些数据放入下拉列表中? – Kasaku