Best way to handle this scenario in ajax?

Best way to handle this scenario in ajax?

Hello,

If you navigates away from the page either by refreshing, clicking a link, or changing the URL in the browser during ajax processing, it throws error..so found that I can simply catch like this for this case..

$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
          if (jqxhr.readyState == 0 || jqxhr.status == 0) {
                //...page navigated away ..
               return;
            } 
});

One thing also I noticed, when my server went down, the status value is also 0...
I would like to distinguish those two cases..... so if the server went down, I would like to show some meaningful messages to users, but NOT for page navigation away during the processing.

is there any elegant way to do this?

Thanks,