Is there any way to put a return from within a callback into a global
variable? I'm trying to retrieve JSON-values in one statement, and
output them in another statement; and code looks like this:
var _json;
function load_comments(id, params) {
if (typeof id != 'number' && typeof id == 'object' && params == null)
{
// Only the params were specified.
_params = process_params(id);
$.getJSON(paths.get_comment, _params, function(data) { _json = data;
return _json; });
console.info('1 : $.getJSON(' + paths.get_comment + ', ' + _params +
')');
}
}
function display_comments() {
load_comments();
$.each(_json.comments, function(comment) {
$("#recent-comments-list").append("<li>" + comment.content + "</
li>");
});
}
Unfortunately, _json seems to remain undefined... What am I doing
wrong? Or is there really no way to accomplish this?
Thanks a lot!
Niels