Hi,

If it's *completely unavoidable*, you can make the call synchronous.
See the options page[1] for details.  Making the call synchronous will
lock up the UI of most browsers during the processing of the call.

So:
* * * *
function getResult() {
    var result;

    // Default to a failure
    result = (your failure return value here);

    // Do the request synchronously
    new Ajax.Request(url, {
        // Lock up the browser until this completes
        asynchronous:  false,

        // On success, set our local variable to the result from the
response
        onSuccess:     function(resp) {
            result = resp.responseJSON.result;
        },

        // Report failures and exceptions
        onFailure:     function() {
            reportError('Request failed');
        },
        onException:   function(req, ex) {
            reportError('Error: ' + ex);
        }
    });

    // Done
    return result;
}
* * * *

(The above assumes your request returns JSON.)

But again, if you can possibly avoid it...

[1] http://prototypejs.org/api/ajax/options

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Jan 21, 6:04 pm, bigyellow <redlocyel...@gmail.com> wrote:
> I read through the response in October from bluezehn regarding this
> subject but couldn't quite make sense of it. Here's the deal. I've set
> an image to draggable and set revert equal to the result of a
> function. If the function returns true, the image snaps back,
> otherwise it doesn't. This works with no problem. However, in reality
> I would like the function to make an ajax call and return true or
> false depending on the results of that ajax call. Bottom line, I've
> created an ajax chess game and right now you have to click where the
> piece is and click where you want it to go. It works, but I'd prefer
> drag and drop functionality.
>
> I understand the asynchronous nature of javascript, but how do I have
> an ajax call actually return a value to another calling function?
> Thanks in advance for any help you can give.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to