Here variable data should hold the data getJSON-method returns. But is there something wrong? It seems the data is empty.
$(function(){
$("#subjectgroups").change(function(){
$.getJSON("/getSubCategories?id="+$("#subjectgroups").val(), function(data){
var options = '';
for (var i = 0; i < data.length; i++) {
options += '<option value="' + data[i].id + '">' + data[i].description + '</option>';
}
$("#mainsubjects").html(options);
})
});
});
When I type the getJSON url on browser, I get the json elements just right, example:
[{"description":"Religion","id":34},{"description":"uskonto","id":9}]
remove the comma in
"/getSubCategories?id=",+$("#subjectgroups").val()