dropdown values from return jquery ajax success
in jquery ajax, i get the values from the database and need to display in drop down. first i pass the id and fetch the level. with tat level id and name, again i fetch the values related to the selected level and display in the dropdown from the return jquery ajax object.
not inserting the result in drop down (testing function)
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;
}
and using the开发者_开发技巧 c# class
public class Level
{
public int Id { get; set; }
public string Name { get; set; }
public List<ListEntity> Value { get; set; }
}
Your getDropdownValues function requires you to pass in the LevelId
and selectedLevel
parameters, but when you call it from your testing function you are not passing these in. So presumably your GetValues service is failing to return any results.
精彩评论