#1358 new
Nathan Trevivian

False positive returned from Ajax.Request#success function

Reported by Nathan Trevivian | June 18th, 2012 @ 03:54 PM

Consider the following success and getStatus functions currently part of Ajax.Request:

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

  getStatus: function() {
    try {
      if (this.transport.status === 1223) return 204;
      return this.transport.status || 0;
    } catch (e) { return 0 }
  },
...

I have discovered when working with a web-app in the Tomcat container (no web server) that if you kill off the server side then make an Ajax request this line from the getStatus function, above:

      return this.transport.status || 0;

returns 0, which means that the return !status part of the success function, above, will return true.

The net result of this is that the respondToReadyState function, also in Ajax.Request, will call onSuccess (if defined in configuration) rather than onFailure.

I would have thought that if a request could not communciate with it's target then it should call onFailure, not onSuccess, am I wrong?
This could pontentially be fixed by changing that part of onSuccess to check for true-boolean false (status === false), but I'm not entirely sure what the first part of the original expression was trying to achieve anyway...?

I'm raising it as an issue because I believe it's wrong to return to onSuccess when the request has actually failed.

Comments and changes to this ticket

  • Nathan Trevivian

    Nathan Trevivian June 18th, 2012 @ 06:05 PM

    This is actually practically a duplicate of #437.
    I now know why it's returning a success if there's no status - namely because the request has potentially been aborted.
    To all intents and purposes the request has not succeeded if it's been aborted either, IMHO.
    Feel free to link this ticket with that one and close if it appropriate. (Not sure how to do that).

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Referenced by

Pages