I am trying to populate values for html drowpdown using JQuery from webapi url. JSON returns value and I've verified it using alert function. But, when I bind those into dropdown it is not populating the values.
Chrome developer tool console shows err:
"Cannot read property '0' of undefined ".
@section scripts {
<script src="~/Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-ui-1.8.24.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var testDdl = $('#test');
$.ajax({
url: "/api/Values",
type: "Get",
success: function(data) {
for (var i = 0; i < data.length; i++) {
testDdl.append($("<option/>"), {
value: this.data[i],
html: this.data[i]
});
}
},
error: function(msg) { alert(msg); }
});
});
</script> }
<body>
<form>
<select id="test"></select>
</form> </body>
Please help me to resolve this.
console.log(data)
give you if you place it inside the success callback? – Kristoffer Jun 23 at 19:39