PDA

View Full Version : progress bar with php



comicway
3 Feb 2010, 12:41 PM
Hello all,

Here is a small question for you...

I've created a progress indicator with an ajax request, here is my code


var ajaxWaitMessage = null;

Ext.Ajax.on({
"requestcomplete": function(conn, response, options){


// Hide AJAXWAIT -- added flag which checks for suppression 04/07/2009
if (!options.suppressScreenLock && ajaxWaitMessage.isVisible())
{
Ext.DomHelper.overwrite (ajaxWaitMessage,
{html: 'Redirecting ...'},
true
);
//window.location.replace("test.php");

}

},
"beforerequest": function (conn, options) {
if (!options.suppressScreenLock)
{
if(!ajaxWaitMessage) {
ajaxWaitMessage = Ext.DomHelper.insertFirst(
document.body,
{id: 'waiting_message'},
true
);

Ext.DomHelper.append(ajaxWaitMessage,
{html: 'Please wait" />'},
true
);
}

ajaxWaitMessage.show();
}
}

});

Ext.Ajax.request({
url: 'api.php?ac=test',
timeout:9999999,
success: function(responseObject) {
alert(responseObject.responseText);
},

params: { id: '13' }
});

});



My code php is displaying message BEFORE the end of loading page with this code


if (ob_get_level() == 0) ob_start();

for ($i = 0; $i<10; $i++){

echo "<br> Line to show.";
echo str_pad('',4096)."\n";

ob_flush();
flush();
sleep(2);
}

echo "Done.";

ob_end_flush();


Can you tell me how i can display during the ajax request the html output of the php file?

Thanks for your help
Christophe

mitchellsimoens
3 Feb 2010, 3:01 PM
Well, the Ajax request is only going to poll your PHP script once.

joefox
3 Feb 2010, 8:40 PM
Well, the Ajax request is only going to poll your PHP script once.

YOu beat me to it.

comicway
3 Feb 2010, 10:28 PM
Is there any other method i can use to print info from php?

Thanks
Christophe

evant
3 Feb 2010, 10:55 PM
It's not worth the trouble. You're better off just showing a loading indicator.