在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