title: jQuery - Ajax call failing to reach success callback but still functioning
body: <p><strong>My question:</strong> 
  My ajax request downloads a generated file as expected but never fires the success callback and fires the complete callback immediately. How do I get a function to be triggered by the completed download of the file?</p>
  
  <p><strong>Some details:</strong>
  I have a form that submits to itself and calls a function that generates a file for download.</p>
  
  <p>The ajax:</p>
  
  <pre><code>var prepdata = 'start=' + startdata + '&amp;end=' + enddata;
  $.ajax({
      url: 'index.php',
      data: prepdata,
      success: function(){console.log('success.');},
      complete: function(){console.log('complete')}
  });
  </code></pre>
  
  <p>So you submit a form (in index.php), the form submits to the same page (index.php) and passes some $_GET paramaters. The presence of the $_GET params triggers a function that gets some data from the database, formats a file and outputs it with:</p>
  
  <pre><code>header("Content-type: application/vnd.ms-excel");
  // more headers here... the correct ones, trust me
  print $data;
  exit;
  </code></pre>
  
  <p>Now, all of this works, resulting in a downloaded file. The problem is that I want to fire a javascript function (that removes a "...loading" symbol) after the page has been downloaded. What happens is that the "success" callback is never triggered while the "complete" call back is triggered immediately after submitting.</p>
  
  <p>How do I trigger a function after the data has been downloaded?</p>
  
  <p>Any ideas? One more thing, in Safari I see the following console error:</p>
  
  <pre><code>GET http://mysite.com/somedir/?start=1&amp;end=2 Frame load interrupted
  </code></pre>
  
  <p>Which I assume has something to do with the headers being output and interrupting the flow of things, and which I assume is why the ajax is failing. Just don't know how to work around it.</p>
  
  <hr>
  
  <p>EDIT: Nothing worked. :( I tried loading into an iframe but couldn't get the load event to trigger because of the frame load interrupted issue. In the end I just faked it with a timeout that runs after a set period that is slightly longer than the longest download I can reasonably expect.</p>