how to show progress bar

Posted on 2013-05-24
Medium Priority
Last Modified: 2013-06-02

I have web page that submit some information to the server (postback the page). On the server, I  launch an external program to do some processing (async) and return to current page. The external  does some work and write the percent complete and action to a file.  I would like the  user to be inform of the process. So, when user return to the current page again , I would like to show a status bar with progress.and keep then on on the page until  job is complete
 When the user return to the page  how do I show the progress bar..Do I have re-direct to another page and show the status  ? or can I show a modal dialog with a progress bar in the current page (not sure how to do this action)

[php, jquery]

Thanks for the help
Question by:SiemensSEN
LVL 62

Accepted Solution

Julian Hansen earned 1200 total points
ID: 39196238
What you do is on the page you have some javascript that runs on a setInterval

This makes an AJAX call back to the server to fetch the percent complete - how you display the results is entirely up to you - here is some sample code to demonstrate the point

Here is sample code (you can view it in action here http://www.marcorpsa.com/ee/t236.html)

The HTML file
<!doctype html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var progressWidth = 0;
var url = "progress.php";
var progint = setInterval("progressUpdate()", 3000);

$(function () {
  progressWidth = $('#progressBarContainer').width();

function progressUpdate()
  $.get(url,'', function(data) {
    val = (data.percent - 1) * progressWidth;
    $('#progressBarContainer').animate({backgroundPosition: val + 'px 0'}, 150);
    $('#progressBarContainer').html(parseInt(data.percent * 100) +'% complete');
    if (data.percent >= 100) clearInterval(progint);
  }, 'json');
<style type="text/css">
#progressBarContainer {
  width: 200px;
  height: 20px;
  position: relative;
  text-align: center;
  z-index: 100;
  border: 1px solid #efefef;
  font-size: 12px;
  font-family: arial;
  line-height: 20px;
  background: pink url(images/progress.gif) no-repeat -190px 0;
  color: #eee;
<a href="progress.php?reset">Reset</a>


<div id="progressBarContainer">
  0% complete

Open in new window

The PHP simulator
if (isset($_GET['reset'])) {
  $_SESSION['progressBar'] = time();
  header('location: t236.html');

$data = array('percent' => 0);
if (isset($_SESSION['progressBar'])) {
  if (empty($_SESSION['progressBar'])) {
    $_SESSION['progressBar'] = time();
  $val = time() - $_SESSION['progressBar'];
  if ($val > 30) $data['percent'] = 1;
  else {
    $data['percent'] = $val / 30;
else {
  $_SESSION['progressBar'] = time();

Open in new window

Background image for progress attached

Author Comment

ID: 39197190
Thanks you  for the answer and the sample code. However, I  need your advise on how to do the navigation.

The user complete the form and submit the request to server. I could forward the user to a new page and display the status bar but  I willl have to disable the 'Browser back' option until the job is done

Is it possible, to redirect the user to the same form and popup a display a modal dialog box with the progress bar

The input form is postback to the server and does not use AJAX to post..

Or would you suggest a different method

Assisted Solution

AnuTiji earned 100 total points
ID: 39198957

Before posting the data to the server, show progress bar indicator.When you post data to the server, write a value to the cookie and from client side by using timer check whether there is value in the cookie. If the value is present in the cookie, hide the progress bar.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Assisted Solution

vid_yag earned 100 total points
ID: 39201202
Hello SiemensSEN,

Best thing would be to show progress bar on the same page inside modal box and use setInterval to fetch updated data on some 1-2 seconds interval. Once external program completes the process you can either hide modal box or trigger some page refresh using js.
LVL 62

Expert Comment

by:Julian Hansen
ID: 39201702
The solution depends on what you want to achieve.

A) You want to show a progress bar on a particular page until a particular process is done - but user can (will) browse to other pages in the interim

B) You want to stop navigation on the site until the process is finished showing a progress bar while the background process is incomplete

Which of these (or is there another option) are you wanting?

Author Comment

ID: 39202121
Thanks for your help..

I would like the user to wait for the job to complete. ... Option B
LVL 62

Expert Comment

by:Julian Hansen
ID: 39202282
Ok - obviously taking into account that you cannot force the user to stay on the page - the user can browse away and return in which case do you want to cater for this i.e. if a user hits the back button - what happens - do you want to force a redirect back to the status page?

If the user browses away and returns - do you want to force the user to a specific page with a status.

Modal popups in browsers are simulated - they are not true modals - you are just hiding the rest of the page behind a div on top of which sits the div that contains your code - so you need to take the above questions into consideration - there is more to this than just poping a pseudo dialog.

The code I posted earlier is all you need on the page - you can locate it in a div which you can style to be a popup - you can also have it so that

a) You are always redirected to this page if there is a status pending
b) each time you return to the page the updated status is shown and progress continues - as per the posted example.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question