Posted by the DtTvB on 06/23/06 12:40
I have one, without using AJAX.
1. Put this code in the header:
<div id="liveProgress"></div>
2. In your PHP code, add this function:
function setProgress($x) {
echo "<script type=\"text/javascript\">"
. "document.getElementById('liveProgress').innerHTML = '$x';"
. "</script>";
flush();
}
3. In your loop, type some code like this:
setProgress("Loading... ???%");
Edit message above to whatever you want.
Note that calling too much times of setProgresss function may extremely
slowdown client's browser and eats huge amount of bandwidth. I
recommend to update status every 50-100 loop.
------------------------------------------------
// Example Code:
<html><head><title>Progress Test</title></head><body>
<div id="liveProgress"></div>
<hr /><?php
function setProgress($x) {
echo "<script type=\"text/javascript\">"
. "document.getElementById('liveProgress').innerHTML = '$x';"
. "</script>";
flush();
}
$max = 7;
for ($i = 0; $i < $max; $i ++) {
echo 'Loop #' . ($i + 1) . ' of ' . $max . '<br />';
setProgress('Loading...' . round(($i / $max) * 100) . '%');
sleep(1);
}
setProgress('Finished!!');
?>
</body></html>
Navigation:
[Reply to this message]
|