2011-09-07 116 views
0

在jquery ajax中,我从数据库中获取值并需要在下拉菜单中显示。首先我传递id并获取关卡。与tat级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(); 
     $('#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; 
} 

,并使用C#类

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

...你的问题是? – Tomalak

+0

不生成下拉列表。 – user930453

+0

你能编辑你的问题来说明问题出在哪里吗?您是否从服务器获取任何数据?或者你只是不确定如何将这些数据放入下拉列表中? – Kasaku

回答

0

你getDropdownValues功能需要您在LevelIdselectedLevel参数传递,但是当你可以从你的测试函数中调用它,而不是传入这些函数。所以大概你的GetValues服务没有返回任何结果。

+0

通过传递值也下拉是空的。 result = getDropdownValues(LevelId,selectedLevel); alert(result); 它显示为[对象对象],但不显示值 – user930453

+0

然后,该问题似乎与下拉菜单无关,并且与您的ajax调用有关。没有足够的信息来确定可能出现的问题。你有没有实施其他web服务调用罚款?首先让我感到奇怪的是,您正在通过POST调用您的服务。从等式中删除jQuery,并在继续之前确定您的服务正在执行正常。 – Kasaku