Ok, looks like you need a little primer on the whole asynchronous thing. The
onComplete function you pass in to an Ajax.request call gets executed later
(when the ajax call returns from the server). So in your code when you call
the Ajax.request, you are then right away expecting the variable to hold
relevant information, but the onComplete function hasn't been executed
yet... You're just kind of missing the whole asynchronous thing (which is
something we all had to learn to get used to as well).

Now as for the problem... You're right, I kind of overlooked the fact that
you had all this in a function that was expecting to return a value from
this call, so while my suggestion would allow you to correctly evaluate the
value that came from the server, again the outer body of the onOK function
will have already been evaluated. Again, you need to think about the order
of operations, and how this code is actually going to be executed, keeping
in mind that the code keeps right along executing after you call
Ajax.request. By default Ajax.request operates asynchronously, so that means
your code is not going to sit there and wait for the call to come back for
the server. By the time your call comes back from the server, and your
onComplete function executes, all the other code will have been evaluated.
So really the only way to keep your code written how it is would be to make
your Ajax call a synchronous one, otherwise you have to take other measures,
and certainly rethink what's actually going on.

--~--~---------~--~----~------------~-------~--~----~
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