You're correct - it does need more time to process. That's the reason the last result is the only one that seems to provide the expected result. When the script hits the xmlhttp request, it continues processing on past it while the request is "out there" doing it's work. So, what's happening is that the subsequent requests are killing the previous requests.
One solution is to restructure your code to remove the loop. Another solution is to use a queue. I can't find the link for the one I've used, but you might try Googling for ajax request queue.