Answer the question
In order to leave comments, you need to log in
How to clear xhr.responseText on onprogress event?
Hello.
There is a simple PHP code that displays answers in a loop:
ob_start();
$x = range(0, 20);
foreach ( $x as $value )
{
usleep(250 * 1000);
echo $value;
flush();
ob_flush();
}
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
window.onload = function( ) {
$.ajax({
url: '/parser/ajax.php',
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.onprogress = function( event ) {
console.log(xhr.responseText);
};
return xhr;
},
});
};
</script>
0
01
012
0123
01234
012345
0
1
2
3
4
5
Answer the question
In order to leave comments, you need to log in
You just need to clear the buffer before outputting: ob_clean() .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question