trix21 Posted July 17, 2010 Share Posted July 17, 2010 So basically I have a php loop being called. Something like this (keep it simple). foreach($item as $i) { //do some validation stuff } That's simple enough. So what I want to do is update a div while that foreach is going showing which item it's on, kinda like a process update... "1 of 32 complete"... then "2 of 32 complete" etc... I know the basics of making an ajax call but I just can't seem to figure it out... since php is server side and javascript/ajax being client side (browser). Any tips or ideas that could help me out? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 17, 2010 Share Posted July 17, 2010 How long does the main php script typically take to execute each pass through the foreach() loop? The ajax cannot make a http request to the same main php script as that would cause another instance of the script to be started. You would need the php script to update the changing status information in a location (database table, flat-file) where another php script (such as get_status.php) could read it and then the ajax would make http requests to the get_status.php page. You would need to generate a unique process id (perhaps just use the session id if you are already using a session for the visitor) per visitor to identify the correct status information in the http requests so that you could have more than one instance of this process at any point in time. Quote Link to comment Share on other sites More sharing options...
trix21 Posted July 17, 2010 Author Share Posted July 17, 2010 Yeah i figured that's the answer I would get, writing to a flatfile or db and using a setinterval method to check it every so often using open. Thanks for the quick response, and the clear answer. Quote Link to comment Share on other sites More sharing options...
trix21 Posted July 20, 2010 Author Share Posted July 20, 2010 Ok, I had to mark unsolved because I can't seem to get it working. Basically the user would upload a file (csv in this case) and after the upload it does an http request via ajax to run a validation check. So one http request has already been sent out to let's say process() function in a php script. That process function is a foreach loop, it seems that once it gets in that loop and ajax is waiting for onreadystatechange I can't do anything... like call another http request to updater() function in another php script that simply calls the database for which line of the csv it's on ("2 of 89 completed") which would update a div block with innerHTML. After the foreach loop from the first http request is finished ... then it will update the div block with the status from the second http request call. So I'm stuck on this. I know php is server side... is there a way to update the process div block while the foreach is running? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 20, 2010 Share Posted July 20, 2010 No one can actually help you with what your code is doing without seeing all the actual relevant code involved with the problem. 113 different people could have written code that is attempting to do what you state and there could be something different wrong in each of their programs but each of them could produce the same symptom as your's. Quote Link to comment Share on other sites More sharing options...
jonndoe45 Posted July 20, 2010 Share Posted July 20, 2010 Ok you're thinking about this all wrong the for loop will be in a php file that is NOT the main php file that generates the page, it is called by JS/Ajax the for loop will not produce any other output apart from either xml/json data the xml/json data is passed back to the js the js then updates the div with what is passed back Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.