As Tobie pointed out, Ajax requests are *asynchronous*, so the request
fires and then the function exits while the results are being fetched.
This means JSON_REQUEST will finish, and normal program flow will
continue, so the alert(myvar) outside the function will get called,
but, *since the request is still being processed*, myvar is still
undefined.

So you have to wait until the request finishes and onSuccess/onFailure
get called, and then myvar will be made global.

If you need to process myvar, then you have to do it from the on* callback.

Best,
-Nicolas

On Dec 24, 2007 1:19 AM, Aea <[EMAIL PROTECTED]> wrote:
>
> Thanks for the heads up, here's what I have now...
>
>
> function JSON_REQUEST()
> {
> new Ajax.Request('process.php?mode=json', { method:'get',  onSuccess:
> function(transport){myvar = transport.headerJSON, alert(myvar);}
> });
> }
>
> JSON_REQUEST();
> alert(myvar);
>
> Still get an alert with the object, then a warning that myvar is
> undefined.
>
> Can somebody provide an example of how I would get that json object
> out of the onSuccess and into the scope of my program, either as a
> global variable or something that's returned?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to