i have this code which is using an asynchronous AJAX object , xmlhttp
xmlhttp.open(’GET’, url, true);
xmlhttp.onreadystatechange = function ()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        alert(xmlHttp.responseText);
    }
    else
    {
        alert(”Error: Failed request!”);
    }
};
xmlHttp.send(null); 
I know that my problem is that the if condition fails until the readystate reaches 4 resulting in me clicking away an alert box 3 times,
I think that the answer is to test against readystate and status in a loop to avoid this but i am unsure how to write the correct loop.