I am new to using ajax but have been using PHP for awhile. I am curious on how to combine the two.
I have a PHP script on my website that takes awhile to loud because it is performing multiple iterations and many functions.
I want to somehow develop like an ajax script that tells the location of the script. There is one variable throughout the script that is like a progress meter. Somehow I want the text to change every time that variable changes.
Is this possible if so how?
Help is greatly appreciated.
You can save the current progress meter state in a file, ram cache or database and write another script that just returns this state. Then you implement AJAX that retrieves this information and then start a new ajax request and so on until the progress is finished.
I’d suggest something like “long-lived HTTP connection” using AJAX. Pass the state in your ajax request and if the progress didn’t change in PHP, just sleep until it does.
Like this (state in %):
And since there is a timeout for ajax request just start a new request once a request timed out.
I hope this is what you meant.