7
rated 0 times
[
12]
[
5]
/ answers: 1 / hits: 53267
/ 14 Years ago, mon, march 7, 2011, 12:00:00
What's the fastest way to check if my server is online via JavaScript?
I've tried the following AJAX:
function isonline() {
var uri = 'MYURL'
var xhr = new XMLHttpRequest();
xhr.open(GET,uri,false);
xhr.send(null);
if(xhr.status == 200) {
//is online
return xhr.responseText;
}
else {
//is offline
return null;
}
}
The problem is, it never returns if the server is offline. How can I set a timeout so that if it isn't returning after a certain amount of time, I can assume it is offline?
More From » javascript