Ajax.Request's getStatus and success

2 views
Skip to first unread message

Cliff

unread,
Jun 3, 2009, 12:14:58 PM6/3/09
to Prototype & script.aculo.us
Hi,

I have a question regarding the code in Ajax.Request. Specifically,
the "success" and "getStatus" methods.

Here is the code from the latest version for reference:

<pre>
<code>
success: function() {
var status = this.getStatus();
return !status || (status >= 200 && status < 300);
},

getStatus: function() {
try {
return this.transport.status || 0;
} catch (e) { return 0 }
},
</code>
</pre>

In getStatus, it looks like 0 is returned if the current transport's
status is null, undefined or somehow returned as false. In the
success method, the negation of the status is checked for validity; !0
evaluates to true, so if no status defined, the request is deemed
successful.

During a recent project, I ran a test in which I shut down my
application server, and then tried to invoke an Ajax call. In Firefox
3, the underlying transport actually returned a 0 for its status, so
the call was evaluated as being successful, and the corresponding
callback method was invoked.

Given all this, I would like to know whether a 0 status should be
construed as being a successful request. I have not found any
reference to it in HTTP status definitions online. Also, under what
cases do transports not return any status, and are these cases also to
be construed as being successful? Or...am I missing something else
that is at work here?

Any thoughts and insights are greatly appreciated -- thanks in
advance!

Cheers,

Cliff
Reply all
Reply to author
Forward
0 new messages