Is it possible to ping a server from Javascript?

后端 未结 17 1404
礼貌的吻别
礼貌的吻别 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

    There are many crazy answers here and especially about CORS -

    You could do an http HEAD request (like GET but without payload). See https://ochronus.com/http-head-request-good-uses/

    It does NOT need a preflight check, the confusion is because of an old version of the specification, see Why does a cross-origin HEAD request need a preflight check?

    So you could use the answer above which is using the jQuery library (didn't say it) but with

    type: 'HEAD'
    

    --->

    
    

    Off course you can also use vanilla js or dojo or whatever ...

提交回复
热议问题