I have looked around for similar topics but none seem to address the problem I am currently having. I have this JavaScript:
<script type="text/javascript">
http = new XMLHttpRequest();
function fetch()
{
http.open("GET", "script.php", true);
http.onreadystatechange = useHttpResponse;
http.send(null);
}
function useHttpResponse()
{
if(http.readyState == 4)
{
var textout = http.responseText;
document.getElementById("ajax").innerHTML=textout;
}
}
</script>
Extremely basic stuff. PHP-script is a simple loop:
for($i = 0; $i < 30000; $i++)
{
echo 'Hello<br />';
}
This works great. I press a button that has onClick="javascript:fetch()"
and it requests the PHP-script and outputs 30.000 lines of "Hello" in the div with id "ajax".
The problem is that it has to wait until it has run all 30.000 loops. I want it to output the response via the AJAX request after EACH loop so that the list kind of expands as the script is running. Is this possible? How would I do this? Like I said, I have searched but come up empty. I realize this is strictly a cosmetic effect but I would be greatful for any advices!
Thank you