I have a page which uses jquery’s ajax functions to send some messages.
There could be upwards of 50k messages to send.
This can take some time obviously.
What I am looking to do is show a progress bar with the messages being sent.
The backend is PHP.
How can I do this?
My solution:
Send through a unique identifier in the original ajax call.
This identifier is stored in a database(or a file named with the identifier etc), along with the completion percentage.
This is updated as the original script proceeds.
a function is setup called progress(ident)
The function makes an ajax call to a script that reads the percentage.
the progressbar is updated
If the returned percentage is not 100,
the function sets a timeout that calls itself after 1 second.
You could have an animated gif load via
.html()into the results area until your ajax function returns back the results. Just an idea.Regarding the jquery ui progress bar, intermittently through your script you’ll want to echo a numeric value representing the percent complete as an assigned javascript variable. For example…
And below is the function I used to get the progress bar to update its position. A little nuts, I know.
If I had to guess, I bet there is a better way… But this is the way it worked for me when I tested it.