PHP + JQuery / AJAX - 具有百分比的加载器

I have a frontend app where i call a PHP script (lets call it script.php) that takes some time to complete. I want to show (on the client side) the percentage completed.

On the file script.php i can at any time calculate the percentage of jobs completed. I searched a bit and a possible solution should be:

  • On the client side call the script.php file
  • Start a polling operation using another php script to get the percentage from script.php
  • Display this percentage on client side.

My problem is how do i get and "share" this percentage value between the script and the other php file to display on the client side.

What options do i have using JQuery/AJAX (i was trying to avoid the use of cached solutions).

Thanks

All you need on the client side is a javascript function which periodically calls your progress.php script or whatever it's called and get's the latest percent completed. Then you can update the DOM with that value.

Take a look at this thread

jQuery AJAX polling for JSON response, handling based on AJAX result or JSON content