What I need is to redirect to a certain url when an error 401 (Unauthorized) response is received. I have several Ajax calls in my code so I am wondering if there is a general way to listen to all of them and only when that code is returned then redirect to that url?
I would like to include this code in all the pages so when received it redirects without having to edit all the AJAX calls in my code.
EDIT: Basically the other answers won't explain the exact mode
It's simply done by doing this:
<script>
$(document).ajaxComplete(function(response, a){
if(a.status == 401){
return window.location.href = '/whatever/url/you/want';
}
});
</script>
Thank you in advance