Anyway, there is a way to detect whether the failure comes from navigating away or other causes.
$.ajax({
type: "POST",
url: '/test',
cache: false,
data: {
},
success: function(data){
},
error: function(req, status, e){
if (req.status == 0) return;
alert('Cannot connect to the server. Please try again later.');
}
});
On the line 12 is the trick