title: How to write javascript in client side to receive and parse `chunked` response in time?
body: <p>I'm using play framework, to generate chunked response. The code is:</p>
  
  <pre><code>class Test extends Controller {
      public static void chunk() throws InterruptedException {
          for (int i = 0; i &lt; 10; i++) {
              String data = repeat("" + i, 1000);
              response.writeChunk(data);
              Thread.sleep(1000);
          }
      }
  }
  </code></pre>
  
  <p>When I use browser to visit <code>http://localhost:9000/test/chunk</code>, I can see the data displayed increased every second. But, when I write a javascript function to receive and handle the data, found it will block until all data received.</p>
  
  <p>The code is:</p>
  
  <pre><code>$(function(){
      $.ajax(
          "/test/chunked", 
          {
              "success": function(data, textStatus, xhr) {
                  alert(textStatus);
              }
          }
      );
  });
  </code></pre>
  
  <p>I can see a message box popped up after 10s, when all the data received.</p>
  
  <p>How to get the stream and handle the data in time?</p>