Re: onComplete: handleSuccess - What gets passed?

Eric Anderson
Sat, 05 Aug 2006 15:23:12 -0000

Alex Duffield wrote:
> I am curious what gets passed back from an completed Ajax.Request call?

All of the Ajax.Request event handlers receive two arguments. The first
is the XMLHttpRequest object used to make the Ajax request. This is
often referred to as the transport in the Prototype library. You can
find details about this object at:

http://en.wikipedia.org/wiki/XMLHttpRequest

The second argument passed in is a JavaScript data structure created
from a JSON string. This JSON string is received from the X-JSON header
in the HTTP response for your Ajax call.

Finally, all event handlers for the Ajax.Request object are executed in
the context of the Ajax.Request object. That means that the "this"
identifier can be used to query the Ajax.Request object that made the
request.

There is one exception to what I just stated. The onException callback
just receives one argument which is the exception that was generated.

> I am using "onComplete: handleSuccess" in my request:

You may want to consider using onSuccess instead of onComplete.
onComplete executes when the XMLHttpRequest object has completed the
request but that request is not necessarily successful. For example it
could have received a 404 response and still called onComplete. When you
use onSuccess your callback will only be executed when you get back a
successful response from the webserver. You can use onFailure to detect
problems such as 404 responses.

Eric