In order to complete the Ajax request, the condition should be as below:
ReadyState property that defines current state of XMLHttpRequest if equals to four (xmlhttp.readyState == 4 && xmlhttp.status ==200) then data is available and Ajax request will be complete.
Code snippet:
xmlhttp.onreadystatechange = function()
{ if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//Ajax request will be complete if above conditions are satisfied
}
}