Get Progress of PHP Script using jQuery.ajax -


I am using jQuery AJAX to run a php script with:

  jQuery Ajax ({type: "post", url: "my_php_script.php", success: function (feedback) {console.log (response);}, error: function () {console.log ('error ... ');}});  

my_php_script.php loops through an array and runs a function on each product:

  $ count = count ($ Array); $ I = 0; Forex Currency ($ array as $ item) {myFunction ($ item); $ I ++; If ($ i == $ count) {echo json_encode ('all done and success'); }}  

All this works, but usually takes the script to complete approximately 2-3 minutes to complete, so I need to show progress to the viewer, How can I do this while it moves?

I can get a percentage of the loop by adding

  $ percent = intval ($ i / $ count * 100). "%"; Echo json_encode ($ percent);  

In my php loop as many:

  $ count = count ($ array); $ I = 0; Forex Currency ($ array as $ item) {myFunction ($ item); $ Percent = interval ($ i / $ calculation * 100). "%"; Echo json_encode ($ percent); $ I ++; If ($ i == $ count) {echo json_encode ('all done and success'); }}  

But how can I get this value in my jQuery Ajax call?

  $ Ajax ({url: path, xhrFields: {onprogress: function (e) {}}, success: work (feedback) {}});  

This example is expected that it helps.


Comments