$.ajaxSetup({error: onRequestCompleted}); function onRequestCompleted(xhr,textStatus,errorThrown) { location.href = '/login'; }