Using Firefox and Prototype with an AJAX Rails app, the onFailure
function argument will not be called if there is no web server
listening on the port that the AJAX call is being made to. You
have to use the onException call, but the exception is being called
because the transport.status does not exist, and the Mozilla JavaScript
engine throws an exception:
The way to reproduce this problem yourself is to apply this patch,
reload an AJAX Rails app in Firefox, then kill the server and then
try an AJAX call:
Index: public/javascripts/prototype.js
===================================================================
--- public/javascripts/prototype.js (revision 103805)
+++ public/javascripts/prototype.js (working copy)
@@ -714,6 +714,12 @@
var transport = this.transport, json = this.evalJSON();
if (event == 'Complete') {
+ try {
+ alert('Message 1 ' + this.transport);
+ alert('Message 2 ' + this.transport.status);
+ } catch (e) {
+ alert('Exception caught: ' + e.name + ' ' + e.message);
+ }
try {
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
The first alert will succeed, but the next alert will not be called
and the alert in the catch block will be used.
See
http://radio.javaranch.com/pascarello/2006/02/07/1139345471027.html
for more information.
It would be nice if there was a way to catch this failure case
so you can use onFailure when the web server is down instead of
onException, as this error seems to be Firefox specific.
Regards,
Blair