How would I check if a web server is online/offline from my domain? I've already tried an $ajax call with jsonp, but if the server isn't responding with json, then that doesn't work. Is there any other way to get an http response from a server?
Asked
Active
Viewed 1.2k times
0
-
You can see if the [$.ajax call times out](http://stackoverflow.com/a/3543713) – Hans Z Jun 02 '14 at 15:08
-
Are you trying to check if arbitrary web servers are online? Due to the same-origin policy, I don't know if JavaScript can do this. You might need to use your webserver to do this (and then make an AJAX call to your server). – gen_Eric Jun 02 '14 at 15:08
2 Answers
4
Just copied shamelessly from one website for easiness:
<img src="http://site-to-check.com/online.png" alt="status" onerror="this.src='files/offline.png'" />
The setup is:
An online icon (online.png) on the remote server you want to see the status of. An offline icon (offline.png) on the server that is going to show the status page.
If the image on the remote server fails to load, the onerror event is triggered and the javascript rewrites the image tag to show the offline image. You can use relative or absolute paths for the offline image. This snippet is fully compatible with all major browsers, including Internet Explorer down to version 5.5!

Jack_of_All_Trades
- 10,942
- 18
- 58
- 88
-
2Just to be courteous, I copied from: http://khromov.wordpress.com/2012/02/07/minimalist-server-online-status-checker-htmljavascript/ – Jack_of_All_Trades Jun 02 '14 at 15:12
-