Bug Tracker

Opened 8 years ago

Closed 8 years ago

#8441 closed bug (worksforme)

jQuery.ajax should call the error handler on 4xx responses

Reported by: lucas@… Owned by:
Priority: undecided Milestone: 1.next
Component: ajax Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

Description

When a requests returns a 4xx as status code, the specified "error" handler should be called, because 4xx status codes indicate an error: "The 4xx class of status code is intended for cases in which the client seems to have erred" from RFC 2616[1]

[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

$.ajax({
	url: some/url.html, // This page should return, for example, a 403 Permission denied
	error: function() {
		console.log('Error');
	},
	complete: function(jqXHR, textStatus) {
		if(parseInt(jqXHR.status) === 403) {
			console.log('Permission denied');
		}
	}
});

Expected console output:

Permission denied.
Error.

Actual output:

Permission denied.

Change History (3)

comment:1 Changed 8 years ago by jaubourg

Could you provide a proper, minimal, test case using jsFiddle or even a static page on a server you own? Also, what browser do you see this behaviour on? Do you use one or several plugins?

Also, on a sidenote, the expected behaviour would be:

Error
Permission denied

in that order.

comment:2 Changed 8 years ago by jaubourg

Component: unfiledajax

comment:3 Changed 8 years ago by jaubourg

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.