Ciao David,
By default, Ajax requests are asynchronous, and so they get *started*
when you do "new Ajax.Requst" but then they run for a while and
complete later; meanwhile, your code that started the request
continues. So what your anonymous function above returns will be
whatever value risultato has when the function starts, since the
request hasn't completed yet. Later, at a time you cannot predict,
the value of risultato will be updated by the callbacks you've
registered.
You _can_ make requests synchronous if you like (set the asynchronous
parameter to false), but that will lock up the UI of the browser for
the entire time the request is taking pace -- which from what you've
said about availability.php non sembra una buona idea.
This might be useful:
http://proto-scripty.wikidot.com/prototype:how-to-bulletproof-ajax-requests
It's an example of an Ajax request that starts the process of
retriving a record from the server, and then displays that record (or,
of course, an error) on callback.
Basically, when working with lots of asynchronous stuff like this, you
end up modifying your logic so you don't make a function call and
expect an answer back, but instead you make a function call and expect
to handle the result in callbacks.
HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available
On Jan 23, 12:38 pm, "
david.0pl...@gmail.com" <
david.0pl...@gmail.com>
wrote: