0

My goal is to check if a specific webserver is ready. The webserver has a callback script implementd, which returns the ready state. If an error occurs, i'll stop the script and process.

The specific part of the script looks as follows.

var ping = {

  start: function () {
    ping.run('http://192.168.0.1:81/Visu/assets/connection.json?callback=jsonCallback', ping.callback);
  },

  run: function (url, callback) {
    var script = document.createElement('script');
      script.onerror = function () {
      callback(false);
      document.body.removeChild(script);
    };
    script.src = url;
    document.body.appendChild(script);
  }

};

This works so far as expected. The problem is, that te request timeout is much to high for my needs. So if the request is made, it takes about 20 seconds until a timeout occures and the error condition (script.onerror) takes place

Thats why I have the following questions:

  1. Is there a general way to configure the timeout of a HTTP-request in Javascript?
  2. Is there an easy way to stop and remove the script after a specific time?

Thanks a lot for your answers in advance.

hafisch
  • 13
  • 4
  • https://stackoverflow.com/questions/30056006/can-a-timeout-be-initiated-for-script-loading-when-the-server-is-down – James Apr 13 '22 at 13:06
  • I was able to solve it by using a fetch. A fetch can be exited an the timeout can be implemented with time functions. – hafisch Jun 14 '22 at 05:52

0 Answers0