Modify ↓
Ticket #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 | |
| 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: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: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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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