icklechurch
04-11-2011, 11:00 AM
Hi,
I'm trying to call a PHP function from a static web page to get the progress of a file download, but it isn't working.
Basically I want the get_progress() PHP function to be called and give me the return value every 2 seconds on the web page, without having to refresh the webpage.
So here is the code at the top of the webpage:
<script type="text/javascript">
var guid = "<?=$guid?>";
var progress_int = "<?=$job_progress?>";
$(document).ready( function() {
setInterval( function() {
var value = parseInt($('#progress_id').text());
if(value < 100)
{
$.ajax({
type: "POST",
url: "/xml/order_status.php?guid="+ guid,
dataType: "xml",
success: function(xml) {
$(xml).find('order').each(function(){
var progress_int = parseInt($(this).attr('job_progress'));
});
}
});
$('#progress_id').html("" + progress_int + "");
}
else
{
$('#progress_paragraph').html('Your files have been successfully prepared.<br>Please see below for your download links.');
}
}, 2000);
});
</script>
<? flush(); ?>
This calls the following page, order_status.php:
<?
session_start();
require_once '../config/definitions.pso';
header('Content-type: text/xml');
$guid = urldecode($_REQUEST['guid']);
if(isset($guid)){
$xml_file = GET_JOB_ADDRESS . $guid;
$job_progress = get_job_progress($xml_file);
} else {
$job_progress = 0;
}
?>
<order job_progress="<?=$job_progress?>" />
Which should return the progress of the job as an interger that is returned and updated every 2 seconds here:
Order status: <?=$job_status?> (<span id="progress_id"><?=$job_progress?></span>% complete)<br />
I'm new to this so please be patient.
Thanks,
Gemma
I'm trying to call a PHP function from a static web page to get the progress of a file download, but it isn't working.
Basically I want the get_progress() PHP function to be called and give me the return value every 2 seconds on the web page, without having to refresh the webpage.
So here is the code at the top of the webpage:
<script type="text/javascript">
var guid = "<?=$guid?>";
var progress_int = "<?=$job_progress?>";
$(document).ready( function() {
setInterval( function() {
var value = parseInt($('#progress_id').text());
if(value < 100)
{
$.ajax({
type: "POST",
url: "/xml/order_status.php?guid="+ guid,
dataType: "xml",
success: function(xml) {
$(xml).find('order').each(function(){
var progress_int = parseInt($(this).attr('job_progress'));
});
}
});
$('#progress_id').html("" + progress_int + "");
}
else
{
$('#progress_paragraph').html('Your files have been successfully prepared.<br>Please see below for your download links.');
}
}, 2000);
});
</script>
<? flush(); ?>
This calls the following page, order_status.php:
<?
session_start();
require_once '../config/definitions.pso';
header('Content-type: text/xml');
$guid = urldecode($_REQUEST['guid']);
if(isset($guid)){
$xml_file = GET_JOB_ADDRESS . $guid;
$job_progress = get_job_progress($xml_file);
} else {
$job_progress = 0;
}
?>
<order job_progress="<?=$job_progress?>" />
Which should return the progress of the job as an interger that is returned and updated every 2 seconds here:
Order status: <?=$job_status?> (<span id="progress_id"><?=$job_progress?></span>% complete)<br />
I'm new to this so please be patient.
Thanks,
Gemma