开发者

display the values of jquery ajax success result

开发者 https://www.devze.com 2023-04-02 21:48 出处:网络
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 select

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.

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();
    $('#drpe >option').remove();
            for (var i = result.length; i--; ) {
                $.each(result, function (key, value) {
                    $("#drp").append($("<option><开发者_如何学编程;/option>").val(value.Key).html(value.Value));
// it does not display the values in drop down 
//it is empty
                });
}

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 i am using this c# class

public class Level
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<ListEntity> Value { get; set; }
    }


If I undertand correctly your question you are asking how to populate the drop down right? If so and assuming your website return a json result and you create a list like that

{ Text = "Valuename", Value = ValueId }

you can do this:

$('#MyDropDown').empty();
$.each(result, function (index, optionData) {
    $('#MyDropDown').append("<option value='" + optionData.Value + "'>" + optionData.Text + "</option>");
});
0

精彩评论

暂无评论...
验证码 换一张
取 消