I'm trying to do a dropdown using json.
json:
[["a","Apple"],["b", "Berry"]]
JavaScript:
$.ajax({url:'fruit.json'}).done(function(data) {
var items = '<option value="" selected>Select</option>';
$.each(data, function(i, val) {
items += '<option value= "'+val[0]+'" > '+val[1]+' </option>';
});
$('#menu').html(items);
console.log(items); //shows values correctly
});
html:
<script type="text/template" id="menuScriptWrapper">
<select id="menu"></select>
</script>
Why aren't the items being populated in to the drop down menu?
$.ajax({url:'fruit.json'})==>$.ajax({url:'fruit.json', dataType: 'json'})ORdone(function(data) { data = JSON.parse(data);., dataType: 'json'})Did not work. I'm trying your other suggestion.