Hoping someone can help. I'm in the process of learning JQuery and I'm stuck trying to return a value from this function.
To troubleshoot I'm logging on the console that the data is pulled through correctly via JSON and it is, it's just the value that's not returning.
Any advice would be much appreciated!
// Get initial categories
var catstr = $.getJSON("scripts/json-categories.php",displayCategoryData);
function displayCategoryData(data) {
catResult = data;
var str ='';
for(var i=0; i<data.length;i++) {
str+= '<option value="' + data[i].id + '">' + data[i].category + '</option>';
}
console.log(str);
return str;
}
$('#category1').html(catstr);