Reputation: 2480
I try to create a Progress bar wait for server do something. When server finish then processbar will completed.
Here is my js
var pbar4 = Ext.create('Ext.ProgressBar', {
text:'Waiting on you...',
width: 300,
renderTo:Ext.getBody()
});
Ext.Ajax.request({
url: 'getStatus.php',
success: function(r) {
if (r.responseText == 100)
pbar4.updateText('All finished!');
else
pbar4.updateProgress(r.responseText, r.responseText+'% completed...');
}
});
and getStatus.php
$total = 10000;
for ($i = 0; $i <= $total; $i++) {
echo $i/$total*100;
}
But when i run that look like
How to do that thanks
Upvotes: 0
Views: 843
Reputation: 92
In case somebody's looking now, I am also thinking of using a progressbar to monitor my Ajax. As previously mentioned, you cannot loop-print in PHP and read that. I did it like this:
Ext.util.TaskRunner();
, monitoring a server file containing Jand updating progress barCode:
$cnt = 0;
$total = 17; //number of times sendStatus(); was called
$monitorPath = '/path/to/file' . $_REQUEST['fileNameFromExtJS']
function sendStatus()
{
global $cnt, $total, $monitorPath;
$statusMessage = array(
"Tinkering stuff..",
"50% complete..",
"Sending...",
"Done!");
$statusMessage = $statusMessage[$cnt];
$cnt ++;
$str = '{"count": '.$cnt.', "total": '.$total.', statusMessage: "'.$statusMessage.'"}';
file_put_contents($monitorPath, $str, LOCK_EX );
}
Reference:
How to update Extjs Progress Bar with JSON results?
Progress bar in your web application, ExtJS / JAVA
Upvotes: 0
Reputation: 5712
What you have here is confusion about how ajax reacts with the page on the server. More specifically that pages aren't as stateful as you imagine them to be.
What you are assuming (or wanting) to happen:
What is actually happening is quite simple:
To fix this issue you actually need to have the PHP page somehow be stateful as to the progress you want to represent here. This can be done by having PHP start a process (new thread, not sure if php has this) that writes numbers to a file on the first request and then have subsequence requests from the webpage read the last number in the file and have it return it. You could also use a database to do something similar.
Upvotes: 2