【问题标题】:display the values of jquery ajax success result显示 jquery ajax 成功结果的值
【发布时间】:2011-09-07 18:28:44
【问题描述】:

在 jquery ajax 中,我从数据库中获取值并需要在下拉列表中显示。 首先我传递 id 并获取级别。使用 tat 级别 ID 和名称,我再次获取与所选级别相关的值并显示在下拉列表中。

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;
}

我正在使用这个 c# 类

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

【问题讨论】:

    标签: c# jquery html ajax


    【解决方案1】:

    如果我正确理解了您的问题,您是在问如何填充下拉列表,对吗? 如果是这样并假设您的网站返回一个 json 结果并且您创建一个这样的列表

    { Text = "Valuename", Value = ValueId }

    你可以这样做:

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

    【讨论】:

      猜你喜欢
      • 2011-03-19
      • 1970-01-01
      • 2011-11-18
      • 2010-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多