2011-09-07 146 views
0

的值,我从数据库获取值并需要以下拉菜单显示。 首先我传递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(); 
    $('#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; } 
    } 

回答

0

如果我undertand正确你的问题你问如何填充下拉吧? 如果是这样,并假设您的网站返回JSON结果与您共创像

{文本=“VALUENAME”,值=值Id}列表

,你可以这样做:

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