If your server code has a way of sharing the state of the application (for example, $ _SESSION in PHP), you can make 2 separate requests, one of which requests data, and one that checks the progress of the first request. Repeat the second timer request until the first completion and update $ _SESSION (or whatever works in your server code) as each element is processed.
For example: The start page should start a session, so subsequent AJAX calls have a cookie and can access shared data:
<?php session_start(); session_write_close(); // close the session so other scripts can access the file (doesn't end the session) // your page content here ?>
First AJAX call to start processing:
<?php function updateSession($count){ session_start(); // open the session file $_SESSION['progress'] = $count; session_write_close(); // let other requests access the session } // as you process each item, call the above function, ex: for ($i = 1; $i <= 10; $i++) { updateSession($i); } ?>
The second AJAX call (repeated every X seconds) is as follows:
<?php session_start(); // open the session file echo @$_SESSION['progress'] or 0; // echo contents or 0 if not defined session_write_close(); // let other requests access the session ?>
Sorry, I donβt know ASP.NET, but I hope this code is useful to you.
Quickdanger
source share