Sunday, 15 February 2015

Binding values to HTML dropdownlist using JQuery with ASP.NET MVC WebAPI - Cannot read property '0' of undefined -



Binding values to HTML dropdownlist using JQuery with ASP.NET MVC WebAPI - Cannot read property '0' of undefined -

i trying populate values html drowpdown using jquery webapi url. json returns value , i've verified using alert function. but, when bind dropdown not populating 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) { (var = 0; < 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 resolve this.

if info object right (it have array of strings) should work:

success: function(data) { (var = 0; < data.length; i++) { var alternative = $("<option/>"); option.attr("value", data[i]).text(data[i]); testddl.append(option); } },

here fiddle of in action: http://jsfiddle.net/aq8x5/5/

jquery html asp.net-mvc asp.net-web-api

No comments:

Post a Comment