A Programmer's Dream

Failures in Ajax

Posted by Stephen Wrighton on 23 Jun 2008

I use the Prototype JavaScript library a lot.

Of course a prime use of the library is its AJAX functionality. I like it, and prefer it immensely over the Microsoft implementation found in AJAX.NET.

There is one issue though--and it's a documentation issue. Mainly, the Prototype JS API documentation does not clearly state how to view the error message one would receive on a FAILURE.

Since I primarily use this blog as a place to store things that I may need again in the future, here's the relevant code:
function failure (transport){alert(transport.responseText); }
Amusingly, simple, no?

The parameter passed in is your standard AJAX RESPONSE object from the Prototype library, so you have a number of other options that you can utilize outside of just the responseText. In fact it's the exact same object passed to the success methods and all the other callback methods that are exposed via the AJAX REQUEST method.

Tweet me @kidananubix if you like this post.

Tweet