I use the following to catch an unauthorized access and force a login:
$.ajaxSetup({
statusCode: {
401: function(){
//do stuff
}
}
});
Works great… when accessing resources on my servers (domain), but now I’m attempting to use 3rd party API resources via ajax calls and their 401’s are caught by this as well. So, how might I either:
- rewrite the above code to only catch 401’s from my domain, or
- make an $.ajax() call with an exception to the above code (use a different error handler)
Thanks much!
Through experimentation I discovered the answer. $.ajaxSetup() basically sets a default for any $.ajax() requests. However, the global setup can be overridden for a specific request like so: