AJAX Progress bar

A

Arancaytar

I am working on a servlet that takes fairly long to process, and I
would like to keep the user updated on the progress with a status bar.

I have already finished the necessary javascript and servlet code: The
local script regularly polls the servlet, which uses the session to
check on the progress of the other program and reports back with an
XML file. The local script then updates the progress bar as necessary.

This works nicely until I actually place it into a form. Apparently,
submitting a form and "leaving" the current page in the browser
somehow suspends the Javascript until the new page is built, which
means that nothing happens while the servlet result page is loading.
How can I make the progress bar script run until the server actually
sends a response to my form submission, and the page is rebuilt?
 
S

SAM

Arancaytar a écrit :
I am working on a servlet that takes fairly long to process, and I
would like to keep the user updated on the progress with a status bar.

I have already finished the necessary javascript and servlet code: The
local script regularly polls the servlet, which uses the session to
check on the progress of the other program and reports back with an
XML file. The local script then updates the progress bar as necessary.

This works nicely until I actually place it into a form. Apparently,
submitting a form and "leaving" the current page in the browser
somehow suspends the Javascript until the new page is built, which
means that nothing happens while the servlet result page is loading.
How can I make the progress bar script run until the server actually
sends a response to my form submission, and the page is rebuilt?

a gif-anim ? showed/hidden when necessary.


function progressBar(yesNo) {
if(yesNo)
myBar = setInterval(function(){$('bar').innerHTML += '+';},300);
else { clearInterval(myBar); $('bar').innerHTML = '';}
}

function queryHttpRequest ( url, argts ) {
progressBar(true);
http_request = new ... blah

if(http_request) {
blah
http_request.onreadystatechange = function() {
progressBar(false);
blah ...
};
blah ...
}
}

Really the JS waiting bar is blocked during the request ?
I can't test because I havn't slow requests.
 
T

Thomas 'PointedEars' Lahn

Arancaytar said:
This works nicely until I actually place it into a form. Apparently,
submitting a form and "leaving" the current page in the browser
somehow suspends the Javascript until the new page is built,

It destroys the Global execution context of the corresponding document and
creates a another one for the target document.
which means that nothing happens while the servlet result page is loading.
How can I make the progress bar script run until the server actually
sends a response to my form submission, and the page is rebuilt?

A. Don't. User agents have built-in progress display.

B. Use another Window object in which the response document is displayed.
That may be one created by an `iframe' element.

C. Use XMLHttpReqest.

You should provide a fallback if B uses client-side scripting, and for C.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top