Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10030 (new defect)

Opened 2 years ago

Last modified 1 year ago

[PATCH] Ajax.Request allows status 0 on non file/ftp urls.

Reported by: tbeck Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: normal Keywords: 1.6.0.3
Cc:

Description

It appears to me that the success() function in Ajax.Request is broken. The current (trunk) version looks like this:

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

So if the status is undefined or 0 success() returns true, which doesn't sound right to me.

I'm thinking it should be something like:

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

I haven't tested this change on the edge, but I have made the change on 1.5.1 and it works. The 1.5.1 function looks like this.

 success: function() {
    return this.transport.status
        && (this.transport.status >= 200 && this.transport.status < 300);
  },

This all came up because according to http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/#xmlhttprequest, Opera appears to be in violation of the XMLHttpRequest spec, specifically:

"If the status attribute is not available it MUST raise an exception. It MUST be available when readyState is 3 (Receiving) or 4 (Loaded). When available, it MUST represent the HTTP status code (typically 200 for a successful connection)."

I was getting the case (in Opera) where readyState = 4 and status = 0. Clearly this is wrong, but in any case prototype was returning true for success() when clearly the ajax request was not successful. The actual return status was 504.

Attachments

ajax_status0_fix.diff (1.0 kB) - added by jdalton on 04/13/08 17:42:50.

Change History

03/30/08 21:27:10 changed by jdalton

  • summary changed from Ajax.Request.success() possibly broken to [PATCH] Ajax.Request.success() possibly broken.

This patch detects if the given url starts with ftp: or file: or if the url is relative and the window.location.href contains ftp: or file: and allows status 0 for those cases only.
http://developer.mozilla.org/en/docs/XMLHttpRequest


Passes current unit tests. (Didn't check if there was a test for status 0 or not)

03/30/08 21:27:58 changed by jdalton

  • summary changed from [PATCH] Ajax.Request.success() possibly broken to [PATCH] Ajax.Request allows status 0 on non file/ftp urls..

04/02/08 14:48:52 changed by jdalton

  • keywords set to 1.6.0.3.

04/03/08 13:29:14 changed by jdalton

04/13/08 17:42:50 changed by jdalton

  • attachment ajax_status0_fix.diff added.

06/10/08 22:36:48 changed by Thomas Bachem

Firefox (at least 2.0.0.14) does cancel all AJAX request when you leave a page (i.e. clicked on a link) and does also set status to 0. This however should not trigger onFailure (and of course also not onSuccess as of Prototype 1.6.2), but more an onCancelled event, because you may not want to throw an error then but i.e. to just silently ignore it. Is this issue known?

06/11/08 09:29:23 changed by Thomas Bachem

I noticed btw that my issue is also related to ticket #9490 (http://dev.rubyonrails.org/ticket/9490).