Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#9808 closed bug (invalid)

.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.

Change History (6)

comment:1 Changed 8 years ago by mattelacchiato

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".

comment:2 Changed 8 years ago by addyosmani

Cc: jaubourg added
Component: unfiledajax
Priority: undecidedlow
Status: newopen

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

comment:3 Changed 8 years ago by timmywil

Milestone: None1.next

comment:4 Changed 8 years ago by jaubourg

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.

Last edited 8 years ago by jaubourg (previous) (diff)

comment:5 Changed 8 years ago by mattelacchiato

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

comment:6 Changed 8 years ago by timmywil

Resolution: invalid
Status: openclosed
Note: See TracTickets for help on using tickets.