Skip to main content

Bug Tracker

Side navigation

#9808 closed bug (invalid)

Opened July 12, 2011 03:33PM UTC

Closed July 15, 2011 03:52PM UTC

Last modified March 14, 2012 04:45AM UTC

.ajax() calls don't catch 401 erros

Reported by: mattelacchiato Owned by:
Priority: low Milestone: 1.next
Component: ajax Version: 1.6.2
Keywords: Cc: jaubourg
Blocked by: Blocking:
Description

Hi,

when calling an url which will return a 401 error, .ajax() doesn't catch this error:

		$.ajax({
			url: "http://url.with.401.error", 
			dataType: 'script',
			statusCode: {
				401: function() {
					alert("foo");
				}
			},
			error: function(xhr, status, errorThrown) {
				alert("bar");
			}
		});

Neither "foo", nor "bar" alerts are shown.

Attachments (0)
Change History (6)

Changed July 12, 2011 03:37PM UTC by mattelacchiato comment:1

Just figured out now, that

dataType: 'script',

is a major part of this bug. When commenting this out, it will alert "bar" and status is "0". But status should be "401".

Changed July 12, 2011 08:52PM UTC by addyosmani comment:2

cc: → jaubourg
component: unfiledajax
priority: undecidedlow
status: newopen

Confirmed. @jaubourg, could you take a further look into the cause?

Changed July 15, 2011 01:37PM UTC by timmywil comment:3

milestone: None1.next

Changed July 15, 2011 02:42PM UTC by jaubourg comment:4

_comment0: Just a wild guess here... the request is cross-domain? \ \ Because same-domain seems to work all-right: http://www.bennadel.com/blog/2228-Some-Thoughts-On-Handling-401-Unauthorized-Errors-With-jQuery.htm \ \ Cross-domain script and jsonp requests do NOT handle errors as document in the API docs.1310741119841610

Just a wild guess here... the request is cross-domain?

Because same-domain seems to work all-right: http://www.bennadel.com/blog/2228-Some-Thoughts-On-Handling-401-Unauthorized-Errors-With-jQuery.htm

Cross-domain script and jsonp requests do NOT handle errors as documented in the API docs.

Changed July 15, 2011 03:46PM UTC by mattelacchiato comment:5

You're right, it's a cross-domain request. Sorry for not reading the docs as I should... :-(

Changed July 15, 2011 03:52PM UTC by timmywil comment:6

resolution: → invalid
status: openclosed