views:

443

answers:

2

I got this php script that generates reports that take 20 to 30 seconds to complete. I would like to add a progress bar, and I have the progress updating in my DB correctly.

The problem is that I cant use jQuery to $.post or $.get while the main page is sitting there loading the report.

I can run javascript, like popup a window that says "please wait" and show a little spinning icon, but firefox refuses to send ajax post/get while the main page is loading.

Any way around this? I tried throwing it all in an iframe but that didn't work ether. (I'm monitoring the traffic using firebug and http live headers)

+3  A: 

You can have jQuery load in the report once your page has loaded, for example:

$(document).ready(function() {
    $('#someDiv').html('<strong>Loading...</strong>')
                 .load('report.html');
});

For a progress bar, check out jQuery UI Progressbar. That said, the manual makes this sound point:

if the actual percent complete status cannot be calculated, an indeterminate progress bar (coming soon) or spinner animation is a better way to provide user feedback.

so if that's the case I would recommend an animated spinner image or such with an appropriate message, for example:

$(document).ready(function() {
    $('#someDiv').html('<img src="images/spinner.gif"/><strong>This could take a while...</strong>')
                 .load('report.html');
});
karim79
+1 - For the link to the progress bar. You can also start to download while the page is being set up, and then when the page is done display the data. Javascript can make ajax calls before the page is done.
James Black
Thanks, it didn't occur to me to load the actual report with ajax. I think that will solve it.
nolanpro
+1  A: 

You might want to consider elementReady. If you make sure your jquery script loads and a portion of your page are written out before the time consuming report begins to process you can use elementReady to kick off some kind of notification. There is no need to wait for the entire document to be ready.

I'm not sure if this will work with the ui progress bar, but I have used it with thickbox to grey-out and block input to the screen until the page has completely loaded and the thickbox throbber .gif works well enough as an activity indicator.

Sorpigal
I'm going to play with that also, i could use php to flush() some instructions to the browser before it gets to the hard report stuff.
nolanpro