Suppose I have a somewhat long-running jQuery Ajax call (say 5 seconds) as follows:
$.ajax({
url: '/LongCall',
type: 'POST',
async: true,
cache: false,
datatype: 'json',
success: function(data) {
alert('Success!');
},
error(xhr, textStatus, errorThrown) {
alert('Error!');
}
});
Now suppose while waiting for my five second process to run the user grows impatient and decides to hit some sort of navigation on my page. What happens in the above call is the user gets the Error alert when he clicks a link.
I do want the error alert to display if there really is an error, but if all that happened is that the user decided to navigate away, I do not want the error alert to display. How can I do this?
In other words, is there some value I can check (xhr.status maybe?) that will tell me that the error that occurred is simply that the process was interrupted so I can know to ignore the error?
Thanks!