I am creating a web application that in a certain moment runs a python script with the exec command in php.
I want to create a progress bar that shows the progress. That python script outputs a json file (it could be txt also) that shows the percentage of the work done.
I would like to transform this value into a progress bar. I found this tutorial and tried to modify it to my purposes but with not so many luck.
This is the modified version of the js script. I can't figure out why is not working, since I don't know a bit of javascript language. The run.php script only executes the command.
Any help will be appreciated.
<?php
session_start();
$path = $_SESSION['path'];
Header("content-type: application/x-javascript");
?>
/*
when the submit button is clicked we will hide the message div. get the input provided by user and start processing.
*/
$(document).ready(function(){
$("#submit-button").click(function(){
/*hide the message div box. since we don't have anything to show at this time.*/
$('#message').hide();
/*
using ajax we will call the server.php script. dataString is the parameter we got from user.datatype is the data type we expect as return. when complete, set the progress bar to 100% and display the message 'complete'.
*/
$.ajax(
{
url : "application/views/pages/run.php",
datatype:"json",
complete:function(){
$("#progressbar").progressbar({
value:100});
$('#message').html('Complete');
$('#message').show();
}
} );
/*
call the updateStatus() function every 3 second to update progress bar value.
*/
t = setTimeout("updateStatus()", 3000);
});
});
/*
.getJSON will get the json string being updated by the server.php in server. every 3 second, the 'total' and 'current' count will be parsed and updated to the progress bar.
*/
function updateStatus(){
$.getJSON('<?php echo $path;?>/progress.json', function(data){
var items = [];
if(data){
var progress = data['progress'];
if(progress>0){
$("#progressbar").progressbar({
value:progress
});
}
}
if(progress < 100){
t = setTimeout("updateStatus()", 3000);
}
});
}
application/json
– ThiefMaster♦ Mar 14 '12 at 9:27progress.json
file is written? By opening it in browser or from console. Are there any js errors in browser? – kirilloid Mar 14 '12 at 9:28