Reputation: 1688
I have two pages. I send ajax call from first page to second page to execute php codes inside it.
execution need long time(1-2 min).how i can create progress bar and show progress percent in first page.
I can calculate progress percent but how show it real time in first page.
firstpage.php
$.ajax({ url: 'secondpage.php',
data: {'q': data},
type: 'post',
success: function(output) {
//some code
}
secondpage.php
<?php
// I have some codes here that can calculate progress percent
// but how to show real time progress percent in firstpage.php
echo $result; //final result(for ajax callback)
?>
Upvotes: 1
Views: 7357
Reputation: 1704
I would use jquery ui progress bar. http://jqueryui.com/progressbar/
And I would use ajax calls to get the percentage completed and use the completed value to update the progress bar while being on the same page. You could perhaps call the progress every 10 seconds or so, get an update, and update the progress bar accordingly.
Upvotes: 0
Reputation: 1137
flush() and ob_flush() is your friend here. Using these together can send the output to the buffer.
Try this example i took from php.net
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 />';
http://php.net/manual/en/function.ob-flush.php
Upvotes: 3