troubleshooting Question

JavaScript: Retry on HTTP GET Connection Timeout

Avatar of ReneGe
ReneGeFlag for Canada asked on
JavaScriptProgramming
11 Comments1 Solution825 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros