Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#14207 closed bug (fixed)

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
Blocked by: Blocking:

Description

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 (8)

comment:1 Changed 10 years ago by dmethvin

Cc: jaubourg added

@jaubourg, thoughts?

comment:2 Changed 10 years 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 10 years 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 10 years ago by jaubourg

Component: unfiledajax
Keywords: xhr-spec added
Milestone: None2.next
Priority: undecidedhigh
Status: newopen

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 9 years 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 9 years ago by dmethvin

Owner: set to dmethvin
Status: openassigned

comment:7 Changed 9 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

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

Changeset: dce2edb3a615f9de158607c9f8be83809373940e

comment:8 Changed 9 years ago by dmethvin

Milestone: 2.next2.1
Note: See TracTickets for help on using tickets.