How to detect if the server shut down during the client has visited a page with javascript?
A request with a forever keep-alive header could do it, but the problem is that fires even when the user navigates away from the page.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Perhaps this is a bit of a naive approach, but you could count the number of response headers when an ajax call fails. With jQuery, for instance, you could do this:
The way I tested this, on my development box, is wrap the above in a
setTimeout()call (with say, a 10 sec. timeout). Load the page. Shutdown server. And then wait for the timeout to expire and do the ajax request.PS.:
$xhr.getAllResponseHeaders()returns a newline delimited string of headers, not an array or object of headers. I overlooked this at first, however, this doesn’t change the outcome of the script. If the string length of$xhr.getAllResponseHeaders()is less than1, no response headers were present.