If the data you are working with is too large for your server memory (for example you have millions of table rows which you should process and get some result.) you may need process it part by part- but with one single click. So we need some javascript-ajax code which should process this sequence itself and corresponding backend code for providing the needed data for each request.
Here is sample code for that:
In javascript part i have written sample js code which runs when you click to some button with “button” ID. It starts and sends its first request to the backend.
Backend gets the first requests and does some operation and returns done percentage. (in this sample there should be 10 steps, so each requests completes the next 10%).
Javascript receives “10” % message from the backend and sends the second requests.
…
When the last message comes from backend, javascript completes the sequence – part by part ajax process is now completed.
Discover more from WP DEV - Elvin Haci
Subscribe to get the latest posts sent to your email.