2013-04-09 81 views
2

我試圖用這個結果集web服務,getYears函數正在返回列表中的年份2013,2012,2011 ....在L ist<string>但是當我把它與ddlyears綁定值上來爲1,2,3,4,5,6jquery webservice foreach循環

$.ajax({ 
     type: "POST", 
     url: "../WebService.asmx/getYears", 
     data:"{}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     async: true, 
     success: function (msg) { 

     for (var myVar in msg.d) { 
      $('#ddlyears').append("<option value='" + myVar.toString() + "'>" + myVar.toString() + "</option>"); 
     } 
    }, 
    error: function (jqerr) { 
     errorCaller(jqerr); 
    } 
}); 
+0

你需要告訴什麼'msg'是什麼? – xdazz 2013-04-09 10:22:18

+0

聽起來像索引 – Andries 2013-04-09 10:27:12

回答

0

試試這個:

success: function (msg) { 

    $.each(msg.d, function (k, value) { 
     $('#ddlyears').append("<option value='" + value + "'>" + value + "</option>"); 
    }); 
}