检查Web服务器是否在线/离线 [英] Checking if web server is online/offline

查看:272
本文介绍了检查Web服务器是否在线/离线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查Web服务器是否在我的域中处于联机/脱机状态?我已经尝试过使用jsonp进行$ ajax调用,但是如果服务器未使用json进行响应,则该操作将无效.还有其他方法可以从服务器获取http响应吗?

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?

推荐答案

仅为了简便起见,仅从一个网站上进行了无耻复制:

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'" />

设置为:

要查看其状态的远程服务器上的在线图标(online.png). 服务器上将显示状态页面的脱机图标(offline.png).

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.

如果远程服务器上的图像无法加载,则会触发onerror事件,并且javascript会重写image标记以显示脱机图像.您可以将相对或绝对路径用于脱机映像.此代码段与所有主流浏览器完全兼容,包括Internet Explorer到5.5版!

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!

这篇关于检查Web服务器是否在线/离线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆