If i recall correctly ...

Failure only gets called on a server error ... like a 404 ...

The failure may be due to a javascript error and would not return the alert 
if that was the case.

On the back .... success only calls when the server has responded...

Ergo there are many things that can go wrong - i've listed a couple below

1. Transit. To/From the server
2. Server side scripts (will return whitespace upon an error - if error 
reporting is turned off) and this is still considered a success by 
javascript.

Also i noticed in the original post that you had asynchronous: true...

It is true by default so you can save a few bites there.

As TJ said in an earlier reply, You cannot return out of the Ajax request as 
it is run asyncronously with the page (meaning [in easy terms] you can 
execute alot of javascript at the same time as the request without locking 
the browser]). To perform what you want to achieve (if i'm getting what you 
want to do correctly) you should create a response handler ... something 
akin to....

onSuccess : function(data) {
myHandler({data:data.responseText.evalJSON,vars:someotherVars});
}

...

function myHandler(options) {
    var ReposnseData=options.data;
    $('someElement').update(ResponseData);


}


Hope this helps...

Alex Mcauley
http://www.thevacancymarket.com


----- Original Message ----- 
From: "Al C" <al.caug...@gmail.com>
To: "Prototype & script.aculo.us" <prototype-scriptaculous@googlegroups.com>
Sent: Tuesday, December 22, 2009 2:29 PM
Subject: [Proto-Scripty] Re: Ajax.Request


I wrestled with asynchronous calls like you have (and quite honestly,
found the structure associated with the onSuccess/onFailure lead to
confusing code)

I eventually settled on using
   var myAjax = new Ajax.Updater( <target>, <url>, {method: 'post',
parameters: pars, evalScripts: true} );
(AFAIK, 'evalScripts: true' does not seem to work with Ajax.Request...
someone please corrected me if I'm wrong)

I then code within the <url> to generate the scripts that should be
spawned on success or failure (and I can set things so that the
scripts don't get called until all of the prerequisite bits are
available).  Depending on the nature of the calls/results, I
occasionally set the <target> to a hidden <div>.

Once I settled on this approach, I had carefully (re-)structure my
code so that calls cascaded properly... i.e., I found that on
occasion, the same functions were getting spawned from
different<url>'s (meaning that the pages could regenerating things
unnecessarily).

Hope this helps,

Al

On Dec 20, 6:35 am, kangur91 <kangu...@gmail.com> wrote:
> My code:
>
> function get_data_default() {
> new Ajax.Request('/adress',
> {
> method:'post',
> asynchronous:true,
> onSuccess: function(data){ return data.responseText.evalJSON
> (true); },
> onFailure: function(){ alert('Something went wrong...') }
> });}
>
> }
> function show(){alert(get_data_default());}
>
> I want to function get_data_default return data recived from OnSucces
> function. How do that?

--

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-scriptacul...@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.



--

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-scriptacul...@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