We help IT Professionals succeed at work.

Java Script, Retry on HTTP GET Connection Timeout

ReneGe
ReneGe asked
on
802 Views
Last Modified: 2013-12-22
Hi there,

I need to add the feature of if the website is unavailable, to wait 10 seconds and try again. If my website is still unavailable, try again 5 times, if still navailable, echo "UnableToConnect" then exit.

IT WOULD LOGICALLY LOOK SOMETHING LIKE THIS (but in Java Script):

SET ConnectCounter=0
:Home
Echo http://www.MyWebSite.com
Send the GET command to the website and ECHO it out
If can't connect to http://www.MyWebSite.com  (
   If %ConnectCounter% GEQ 5 (
   ECHO UnableToConnect
   EXIT
   )
  SET /a ConnectCounter=%ConnectCounter%+1
  Add a delay of 10Seconds
)
Goto home


HERE IS MY ORIGINAL WORKING JAVA SCRIPT:
var request = new ActiveXObject("Msxml2.XMLHTTP");
var notyetready = 1;

request.onreadystatechange=function()
{
if(request.readyState==4)
{
WScript.Echo(request.responseText);
notyetready = 0;
}
}

var objArgs = WScript.Arguments;
WScript.Echo("http://www.MyWebSite.com");
request.open( "GET", "http://www.MyWebSite.com" , true );
request.send(null);

while( notyetready )
{
WScript.Sleep( 100 );
}



Thanks for your help,
Rene
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks Shoikana
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.