Is it possible to ping a server from Javascript?

后端 未结 17 1194
礼貌的吻别
礼貌的吻别 2020-11-22 04:02

I\'m making a web app that requires that I check to see if remote servers are online or not. When I run it from the command line, my page load goes up to a full 60s (for 8 e

17条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 04:40

    You can't do regular ping in browser Javascript, but you can find out if remote server is alive by for example loading an image from the remote server. If loading fails -> server down.

    You can even calculate the loading time by using onload-event. Here's an example how to use onload event.

提交回复
热议问题