title: Save the data received in the XMLHttpRequest to a file
body: <p>I'm actually stuck with a problem of file download from my nodeJs server. I spent many times on other topics, without any success...</p>
  
  <p>I have an app on the client that propose to download some text file. So I put this code for download process:</p>
  
  <pre><code>'click .downloadF': function(event) {
      var $target = $(event.target);
      var file = $target.model();
  
      var download = $.get('/files/download'+'?'+Math.random(),
                          {id:file.id});
    },
  </code></pre>
  
  <p>Up to here...very simple. 
  On my nodeJS side I made that:</p>
  
  <pre><code>app.get('/files/download', function(req, res) {
  var filePath = metrology.DownloadFile(req.query.id);
  
  var filename = path.basename(filePath);
  var mimetype = mime.lookup(filePath);
  
  res.setHeader("Content-disposition", "attachment; filename=Metrology.csv");
  res.setHeader('Content-type', mimetype);
  
  var filestream = fs.createReadStream(filePath);
  filestream.pipe(res);
  </code></pre>
  
  <p>});  </p>
  
  <p>In the Response I get the right text data and the header is correctly set to attachement and file type.
  Response : </p>
  
  <blockquote>
    <p>Connection    keep-alive 
    Content-Disposition   attachment;
    filename=Metrology.csv 
    Content-Type  text/csv 
    Date  Mon, 16 Jun 2014
    15:17:25 GMT Transfer-Encoding    chunked X-Powered-By    Express</p>
  </blockquote>
  
  <p>Content:</p>
  
  <blockquote>
    <p>NoPiece;NoRepetition;Mesure;Resultat; 1;1;1;3; 1;1;2;2; 1;1;3;2;
    1;1;4;2; 2;1;1;2; 2;1;2;2; 2;1;3;2; 2;1;4;2;</p>
  </blockquote>
  
  <p>Now... how can I open a dialog window to save these data into a specified filepath ???</p>
  
  <p>I'm actually debuging on Mozilla, but have to work with IE9/11 too.</p>
  
  <p>Many thanks for help, ideas, suggestions and (maybe) solutions :-)</p>