I need help handling 403 errors that come from my server in $.ajax request of jquery. It sends it as JS error because the request is forbidden but I just want the error to be a part of Ajax response, not just a JS error that fails the entire application. The 403 comes from OAuth2. If any code needs to be provided to clarify my question better, please let me know.
How can I achieve that?
Solution: The best I found to deal with this situation per ajax request is to use statusCode method:
statusCode: {
403: function() {
},
200: function(data) {
}
//other codes. read the docs for more details
}
This works great for all my apps:
(function($){
$(document).on('ajaxError', function(event, xhr) {
if (xhr.status === 401 || xhr.status === 403) {
window.location.reload();
}
});
})(jQuery);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With