Is there a way to handle the error from an ajax request within JQuery such that when the user navigates away from the page, the resulting error is ignored?
$(document).ready(function() {
$.ajax( {
url:'/server/url/',
type: 'POST',
data: {some..data},
success:function(response) { do stuff with response },
error: function(xhr, textStatus, errorThrown) {
// Don't raise this alert if user has navigated away from the page
alert('error');
}
});
I'm curious if anybody knows of a clean way to handle this? I know you could create some logic in a $(window).bind("beforeunload", function(){})
method but I'd prefer if there was a way to handle the situation without doing this since Chrome appears to no longer support it. Is there for example a specific error that is returned in this case?
Thanks.