Bug Tracker

Ticket #14207 (closed bug: fixed)

Opened 20 months ago

Last modified 17 months ago

Ajax error defaults to status 404

Reported by: hvrauhal Owned by: dmethvin
Priority: high Milestone: 2.1
Component: ajax Version: 2.0.3
Keywords: xhr-spec Cc: jaubourg
Blocking: Blocked by:


In jquery 2.0.x, ajax requests that fail without ever contacting a server resolve with jqXHR.status 404 and jqXHR.readyState 4. See  http://jsbin.com/ejeruf/9 for an example.

In 1.x versions they resolve with jqXHR.status 0 and jqXHR.readyState 0 as expected. See  http://jsbin.com/ejeruf/4

The 2.0.x version seems to default to 404 at  https://github.com/jquery/jquery/blob/2.0.3/src/ajax/xhr.js#L75 without checking whether the request was local and not crossdomain, as the 1.x version did in  https://github.com/jquery/jquery/blob/1.10.2/src/ajax/xhr.js#L156

Change History

comment:1 Changed 20 months ago by dmethvin

  • Cc jaubourg added

@jaubourg, thoughts?

comment:2 Changed 19 months ago by hvrauhal

This buggy behaviour makes jquery 2.0 dangerous to use in modern webapps in wireless environments, where it is essential to know the difference between network errors (that should return with status 0) and real 404's returned by the server.

comment:3 Changed 19 months ago by hvrauhal

I could post a patch that just removes the ' || 404 ', but that would leave the refactoring of xhr.js halfway regarding how error statuses are handled in file-protocol. The xhrSuccessStatus-mapping does not take the actual request protocol into account neither, though it appears to me that it should.

comment:4 Changed 19 months ago by jaubourg

  • Keywords xhr-spec added
  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to ajax
  • Milestone changed from None to 2.next

I'm afraid the only actual solution would be to add the local protocol detection code back in. That's the only way we'll be able to differentiate between a 404 and an actual network error.

Let me tag this as xhr-spec. I should really find time to have this dealt with in the XHR spec.

comment:5 Changed 17 months ago by jaubourg

All right, the only solution I see here is to just remove || 404. The only bad side-effect (apart from having a 0 status code for error on local protocols) is a wrong readyState (0 rather than 4) on the jqXHR object. I can live with that.

comment:6 Changed 17 months ago by dmethvin

  • Owner set to dmethvin
  • Status changed from open to assigned

comment:7 Changed 17 months ago by Dave Methvin

  • Status changed from assigned to closed
  • Resolution set to fixed

ajax: Fix #14207. file protocol returns status 0, see #8605.

Changeset: dce2edb3a615f9de158607c9f8be83809373940e

comment:8 Changed 17 months ago by dmethvin

  • Milestone changed from 2.next to 2.1
Note: See TracTickets for help on using tickets.