Adding information to a page at the end of a loop to show progress
I have a loop that runs through a text area's line and processes e开发者_C百科ach line in a loop.
At the moment the page just stays frozen until all fo the data has been processed.
How can I make it so that as soon as a line has finished processing (when it loops back) it adds for instance "Line 1 processed" "Line 2 processed" etc so that the user can see that it is working.
I am using PHP and would like to use jquery as I am already using in on the site.
Thanks
Since you did not specify any details, I'll just take a wild guess of what you can do:
$(document).ready(function(){
//get the textarea value
var value = $('textarea#my_textarea').val();
//split it into lines
var lines = value.split('\n');
//for every line
for(var i = 0; i < lines.length; i++){
//call line_proccesser.php passing a line to it
$.post(
'line_proccesser.php',
{line:lines[i]},
function(){
//when script has worked, printing status info
$("#info").append('Line ' + (i+1) + 'processed<br />');
}
);
}
});
sorry didn't read your question properly the first time..
perhaps this would help Iterating through a PHP array in jQuery?
If you are using ajax to process your request, it will not generate any feedback until all processing has finished so you can either:
- use @Silver Light's solution and split the request in multiple requests (has disadvantages);
- settle for something like a modal overlay (dimming the page) and displaying a spinning wheel to show the user that it is working.
精彩评论