-1

Is there a way to have an ajax script make updates to a html element while the PHP script is being parsed and not only when it has completed? I.e.:

PHP:

<?PHP
echo 'stage 1';
sleep(3);
echo 'stage 2';
sleep(3);
echo 'Finished';
?>

What I would hope to see happen to the html element is that first it says 'stage 1', then 3 seconds later, 'stage 2' etc.

Would flushing the OB achieve what I want or is there a better way of doing this?

imperium2335
  • 23,402
  • 38
  • 111
  • 190
  • 1
    possible duplicate of [PHP - Flushing While Loop Data with Ajax](http://stackoverflow.com/questions/9152373/php-flushing-while-loop-data-with-ajax) – Ryan Jan 17 '14 at 11:43
  • do you mean like this http://jsfiddle.net/jogesh_pi/LnszD/ – jogesh_pi Jan 17 '14 at 11:46

1 Answers1

0

Sorry but to you can do this you need create this logic on the front-end with javascript/jQuery and use only back-end(php) to get the feeds.

setInterval(function(){
    //jQuery code..
    $.ajax({
        url: 'url_to_get_feeds',
        data: {}, //if need put some param on request
        success: function(callback){
            //logic to put call content to html
            //callback recive all content gerenated on the page 'url_to_get_feeds'
            $('body').append(callback)
        }
    })
});
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Guilherme Soares
  • 726
  • 3
  • 7
  • 19