title: Listening for form submit -> file download Event
body: <p>In a JSP file, I have this simple form:</p>
  
  <pre><code>&lt;form action="#" method="post" id="extract_form"&gt;
  </code></pre>
  
  <p>and based on a few <code>select</code> parameters, it returns a .zip file through this piece of code in the Servlet:</p>
  
  <pre><code>ServletOutputStream sos = response.getOutputStream();
  response.setContentType("application/zip");
  response.setHeader("Content-Disposition", "attachment; filename=\"" + zipFile.getName() + "\"");
  </code></pre>
  
  <p>-followed by some <code>sos.write(byteArray);</code></p>
  
  <p>All this is working excellent, but the time it takes to create the zip file is dependent on the form parameters and I would like to display a "Please Wait" blockUI popup on form submit and then this is removed again automatically when the .zip file has been received by the browser.</p>
  
  <p>I have no trouble displaying the popup, but I have a hard time getting it to disappear again automatically after file is received! How do I accomplish this?</p>
  
  <p>If have tried the following:</p>
  
  <p>1: Explicit <code>$.unblockUI()</code> in </p>
  
  <pre><code>jQuery(document).ready(function($) { ... }
  </code></pre>
  
  <p>-but the ready() event is not triggered after .zip file sent, i.e., the .jsp is not reloaded.</p>
  
  <p>2: A solution like <a href="https://stackoverflow.com/questions/5733808/submit-form-and-stay-on-same-page">this one</a>. The success callback function is called, but the .zip file is not downloaded. I think, though, that the .zip file is transferred to the browser in its binary form through the response object passed to the function called on success.</p>
  
  <p>3: scanning the jQuery webpage for events to listen to, but I only found on the triggering of the action (<code>$('#form').submit(...)</code>), not the response thereof.</p>