I am trying to get Comments stored in the Firebase using the below example. The script is looping through the json object and appending the HTML results to a global variable. However, the assignment in the loop does not append to the global variable.
var doccmnthtml = '';
try {
$.getJSON( "https://ocw.firebaseio.com/.json", function( json ) {
for (var key in json) {
if (json.hasOwnProperty(key)) {
// Cannot append to the variable
doccmnthtml += '<b>'+json[key].username+'</b><br/>'+json[key].text+'<br/><br/>';
}
}
});
}
catch(err) {
console.log(err.message);
}
alert(doccmnthtml);