title: Get Progress of PHP Script using jQuery.ajax
body: <p>I am using jQuery's ajax to run a php script with the below:</p>
  
  <pre><code>jQuery.ajax({
      type: "POST",
      url: "my_php_script.php",
      success: function( response ) {
          console.log(response);
      },
      error: function(){
          console.log('error is...');
      }
  });
  </code></pre>
  
  <p><code>my_php_script.php</code> loops through an array and on each product runs a function:</p>
  
  <pre><code>$count = count($array);
  $i = 0;
  foreach ($array as $item) {
      myFunction($item);
      $i++;
      if($i == $count){
          echo json_encode('all done and a success');
      }
  }
  </code></pre>
  
  <p>This all works but the script can generally take around 2-3 minutes to finish so I need to show the progress for the viewer whilst it runs. How can i do this?</p>
  
  <p>I can get the percent of the loop by adding</p>
  
  <pre><code>$percent = intval($i/$count * 100)."%";
  echo json_encode($percent);
  </code></pre>
  
  <p>into my php loop as so:</p>
  
  <pre><code>$count = count($array);
  $i = 0;
  foreach ($array as $item) {
      myFunction($item);
  
      $percent = intval($i/$count * 100)."%";
      echo json_encode($percent);
  
      $i++;
      if($i == $count){
          echo json_encode('all done and a success');
      }
  }
  </code></pre>
  
  <p>But how can i get this value in my jQuery ajax call?</p>