Bug Tracker

Modify

Ticket #9808 (closed bug: invalid)

Opened 23 months ago

Last modified 15 months ago

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

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

comment:1 Changed 23 months 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 23 months ago by addyosmani

  • Cc jaubourg added
  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to ajax

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

comment:3 Changed 23 months ago by timmywil

  • Milestone changed from None to 1.next

comment:4 Changed 23 months 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 23 months ago by jaubourg (previous) (diff)

comment:5 Changed 23 months ago by mattelacchiato

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

comment:6 Changed 23 months ago by timmywil

  • Status changed from open to closed
  • Resolution set to invalid

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.