title: download file using an ajax request
body: <p>I want to send an  "ajax download request" when I click on a button, so I tried in this way:</p>
  
  <p>javascript:</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  xhr.open("GET", "download.php");
  xhr.send();
  </code></pre>
  
  <p>download.php:</p>
  
  <pre><code>&lt;?
  header("Cache-Control: public");
  header("Content-Description: File Transfer");
  header("Content-Disposition: attachment; filename= file.txt");
  header("Content-Transfer-Encoding: binary");    
  readfile("file.txt");
  ?&gt;
  </code></pre>
  
  <p>but doesn't work as expected, how can I do ? Thank you in advance</p>