Robbrad Posted December 21, 2009 Share Posted December 21, 2009 I'm sure this has been asked before but I need to know the best way to approach the challenge What I have at present is a site that completes a task where a PHP script goes and performs a load of actions but doesn't inform the user of its progress What I would like is a page that shows the progress of the PHP script to the user and then when complete redirects them to the result. I've had a brief look at jQuery and mootools but I just don't know where to start :-\ Quote Link to comment https://forums.phpfreaks.com/topic/185915-progress-of-a-php-script/ Share on other sites More sharing options...
roopurt18 Posted December 21, 2009 Share Posted December 21, 2009 You're going to need to use XHR (or AJAX if you prefer) and polling to make this work. XHR is where you use JavaScript to send requests back to the server "behind the scenes" so that the browser page doesn't reload. There are many, many tutorials on XHR so I'll leave it up to you to read about it. My suggestion is make a couple of really simple XHR examples work to just get the feel for what you're doing. As far as your specific question: 1) When the user submits the request, send it via XHR. 2) Start a JavaScript timer and every X seconds send another XHR request to the server to get the status of the original request. 3) The server's response to #2 should tell you in what state the original request is in or if it's finished. 4) Update a portion of the page using HTML DOM to reflect the status gained in #3. #2 and #3 combined are called polling; the JavaScript page is constantly asking the server what's going on with the request: "Are you done yet?" "Are you done yet?" "Are you done yet?" "Are you done yet?" "Are you done yet?" "Are you done yet?" "Are you done yet?" "You are? Great!" Quote Link to comment https://forums.phpfreaks.com/topic/185915-progress-of-a-php-script/#findComment-981838 Share on other sites More sharing options...
Robbrad Posted December 21, 2009 Author Share Posted December 21, 2009 That is great ill get started on something simple and build from there Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/185915-progress-of-a-php-script/#findComment-981869 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.