Couple of thoughts:

1) $.each() is not for moving through an array. (is for doing
something to each matched DOM element) try: for(item in _json)
{ alert('item:'+item);}

2) try defining your global as an object. e.g. var _json = {};

-jason

On Jan 16, 2:17 am, Niels <[EMAIL PROTECTED]> wrote:
> 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

Reply via email to