 <p>The best way to do this (in my opinion) is to actually combine @serge1peshcoff's two options. Write the call as a function that calls itself when the response fails, <em>and</em> set a timeout when doing so. For most purposes, you don't want to send another request immediately after the previous one, you want to wait at least a second or five to prevent spamming the server (you've also given no indication of how many clients you expect. What's bad for your browser is potentially horrible for the server, which may be handling requests even before your web app is fully up and returning 200). </p> <p>Also, setTimeout is a better approach than setInterval, as you explicitly reset it on each round trip. </p> <p>Borrowing from @serge:</p> <pre><code>function tryRequest(numTries) { var responseStatus = 404; var request = new XMLHttpRequest(); numTries = numTries || 0; console.log("Checking if restart has completed. Attempt number: " + numAttempts); request.open('GET', 'applicationurl', true); request.onreadystatechange = function(){ numTries++ if (request.readyState === 4){ console.log("Request Status: " + request.status); responseStatus = request.status; console.log("Response Status: " + request.status); if (request.status != 200) { console.log("Restart has not yet completed! NumberOfTries: " + this.attempts); setTimeout(tryRequest.bind(null, numTries), 5000); // five seconds } } }; request.send(); console.log("Server has successfully restarted"); } tryRequest(); </code></pre>