Use Javascript to send multiple requests to server until server returns 200
<p>I have created a html page which the user views when they are waiting for another application to restart. I have created a javascript script which makes multiple requests to the application until the application returns 200. However, when i try to open my html page, the browser simply crashes. Can anyone see whats wrong with my code: </p>

<pre><code>var responseStatus = 404;
var numberOfTries = 0;
var request = new XMLHttpRequest(); 
while(responseStatus != 200){
    console.log("Checking if restart has completed. Attempt number: " + numberOfTries);
    request.open('GET', 'applicationurl', true);
    request.onreadystatechange = function(){
        if (request.readyState === 4){
            console.log("Request Status: " + request.status);
            responseStatus = request.status;
            console.log("Response Status: " + request.status);
            if (request.status != 200) {  
                numberOfTries++;
                console.log("Restart has not yet completed! NumberOfTries: " + numberOfTries);
            }  
        }
    };
    request.send();
}
console.log("Server has successfully restarted");
</code></pre>