I have a loop that executes in at least few seconds (it waits for about
10 ajax requests to gather all the data).
I would like to tell the browser that the loop is still working and let
the browser do its work.
In past, when I was working in Delphi, I used
application.processMessages() procedure, so my app would stop executing
loop, processed all the windows messages (like mouse clicks etc) and
return to the loop.
Is there any way to pause the loop and let the browser process its
messages, do what the browser usually does, i.e. respond to an click on
the page, and when it's done, return to the loop?
Regards,
Szymon Wilkolazki
You should just be making the requests asynchronously, so there
shouldn't be any loop. When the load callback for each is finished,
continue with whatever you need to do.
You should just be making the requests asynchronously, so there
Yeah, all the requests are asynchronous. When each of them completes,
it increments the counter of responses. I was using loop to wait for
the counter to match number of requests, but I figured better way:
Now I use Prototype's periodicalExecuter to check if the responses
counter match number of requests every second. It does not lock the
browser and do what I want it to do.
Sometimes I still think to much in Delphi and try to translate it to
js, instead of thinking in JS...
Thanks for your reply,
--
Szymon Wilkolazki
A better way may be to just check the counter and call whatever is
necessary in the load callback.
Why? Why not just:
function onResponse() {
++numberOfResponses;
if (numberOfResponses == numberOfRequests) {
allRequestsComplete();
}
}
Igor Tandetnik