If it is possible for you to use the Ajax result (downloaded text) in the onreadystatechange method of the Ajax text, to do so. This is the best way to avoid the conflict.
If you really must use the Ajax result in the statements below that of the Ajax request, then you should have a while-loop below the Ajax request that will be looping and checking to see if the text has been downloaded, before execution of the statements below the Ajax request continues. The xmlHttp.onreadystatechange method should have a statement to indicate to the while-loop if the required result has been received.
Response is taking longer than it should
Here I show you haw to handle the situation when the response is taking longer than it should. The thing to do here is to abort the Ajax request when you believe it has taken too long. You will need to determine, however, how long is too long.
The Ajax object has the method called abort(). This function is used to abort the Ajax request. When the request is aborted, the readyState property is reset to zero and nothing is downloaded; you do not need to worry about the readyState or status properties. The following code segment, typed below the Ajax procedure, aborts the Ajax request after five seconds:
It is not possible to give a clear-cut answer to any of the questions asked in the introduction of the article. There are conditions under which, if you click the Reload button, you will get what you want. There are also conditions when this will not be helpful. Always have the readyState and status property. This will clarify many problems. Do not forget the thread effect of the Ajax request. I showed you in the last section above how to avoid possible conflict.