2011-09-07 5 views
0

의 값을 jquery ajax에 표시하면 데이터베이스에서 값을 가져오고 드롭 다운하여 표시해야합니다. 먼저 ID를 전달하고 레벨을 가져옵니다. tat 레벨 id와 name을 사용하여, 다시 선택한 레벨과 관련된 값을 가져 와서 드롭 다운에 표시합니다.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 결과를 반환하고 해당

{텍스트 = "값 이름", 값 = ValueId} 같은 목록을 만들 수 있도록 가정하면

이 작업을 수행 할 수 있습니다

:

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