0

What Ive tried is this

function checkServer(url, timeout) {
   const controller = new AbortController();
   const signal = controller.signal;
   const options = { mode: 'no-cors', signal };
   return fetch(url, options)
     .then(setTimeout(() => { controller.abort() }, timeout))
     .then(response => console.log('Check server response:', response.statusText))
     .catch(error => console.error('Check server error:', error.message));
 }
 
 var check = checkServer("https://www.youtube.com/xxxxxxxxxxx", 2000)

But the programm I am using doesnt work with it it says: Error: empty expression not allowed (line 6)

Edit: This is not for a website so I cant use html but I can use a server with a php file if thats any help to making this work

GTSkill
  • 11
  • 2
  • 1
    Does this answer your question? [Is it possible to ping a server from Javascript?](https://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-server-from-javascript) – Justinas Sep 22 '20 at 18:59
  • Using mode: no-cors with a domain that obviously requires cors like youtube will block you from accessing the response, see https://developer.mozilla.org/en-US/docs/Web/API/Request/mode – James Sep 22 '20 at 19:02
  • Maybe not related but `setTimeout` does not return a promise or is "then:able" AFAIK – Christian Sep 22 '20 at 19:04
  • You're not checking if error.message exists. I would just stringify the error and log that instead. – Tom Sep 22 '20 at 19:19
  • Ive been looking on the website for any solutions but they all wont work so I made my own post I think Ill have to use a php file for it but no clue on how to do it – GTSkill Sep 22 '20 at 19:22

0 Answers0