title: Displaying progress while waiting for controller in Laravel 4
body: <p>I've got a form that I want to send by ajax-post to my controller. Meanwhile the HTML is waiting for the generation and saving of the records, I want to display the progress (for now just numbers). I really don't understand why the following code doesn't update <code>&lt;div id="progress"&gt;</code> with <code>Session::get('progress')</code>.</p>
  
  <p>Controller:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function postGenerate() {
      // getting values from form (like $record_num)
      Session::flash('progress', 0);
      $i = 1;
      for ($i; $i &lt; $record_num; $i++) {
          $record = new Record();
          // adding attributes...
          $record-&gt;save;
          Session::flash('progress', $i);
      }
      $response = Response::make();
      $response-&gt;header('Content-Type', 'application/json');
      return $response;
  }
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>@section('scripts')
  &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          $('#form-overview').on('submit', function() {
              setInterval(function(){
                  $('#progress').html( "{{ Session::get('progress') }}" );
              }, 1000);
              $.post(
                  $(this).prop('action'),
                  {"_token": $(this).find('input[name=_token]').val()},
                  function() {
                      window.location.href = 'success';
                  },
                  'json'
              );
              return false;
          });
      });
  &lt;/script&gt;   
  @stop
  </code></pre>
  
  <p>HTML:</p>
  
  <pre class="lang-html prettyprint-override"><code>@section('content')
      {{ Form::open(array('url' =&gt; 'code/generate', 'class' =&gt; 'form-inline', 'role' =&gt; 'form', 'id' =&gt; 'form-overview' )) }}
      &lt;!-- different inputs ... --&gt;
          {{ Form::submit('Codes generieren', array('class' =&gt; 'btn btn-lg btn-success')) }}
      {{ Form::close() }}
  
      &lt;div id="progress"&gt;-1&lt;/div&gt;
  @stop
  </code></pre>