1
Well I’m following the example of php.net
<?php
header( 'Content-type: text/html; charset=utf-8' );
echo 'Begin ...<br />';
for( $i = 0 ; $i < 10 ; $i++ )
{
echo $i . '<br />';
flush();
ob_flush();
sleep(1);
}
echo 'End ...<br />';
?>
if I run this script directly in the browser it counts from 1 to 10 showing its result correctly...
However I have a textarea that receives the item , and ajax to send the post and search the result on the screen according to the result
more when I send the items, the flush doesn’t work only returns me the result at the end of the for
<script type="text/javascript">
$(document).ready(function() {
$("#enviar").click(function() {
var nome = $("#nome");
var nomePost = nome.val();
$.post("flush.php", {nome: nomePost},
function(data){
$("#resposta").html(data);
}
, "html");
});
});
</script>
<form action="" method="post">
<textarea name="nome" id="nome" cols="45" rows="5" required placeholder="Sua lista bla bla bla bla..."></textarea>
<br />
<br />
</form>
<button id="enviar" type="submit" class="ls-btn-primary ls-btn-xs">Check !</button>
<br>
</h6>
<br>
<div id="resposta"> Aguardando lista!</div>
Maybe where is
var nome = $("#nome");
Should bevar nome = $("#nome").attr("name");
– Ricardo Cruz
Hello Wender, welcome to [en.so]! Very interesting your question. But maybe you’re using the wrong technique. If you need a mechanism to send data to the customer bit by bit asynchronously, maybe Websockets whatever you’re looking for. However, if the idea is to display something progressively on the screen, the scenario changes completely. It would be better to explain your purpose better. Hug!
– utluiz