title: Download a file by clicking a button
body: <p>This is the HTML:</p>
  
  <pre><code>&lt;button name="download"&gt;Download&lt;/button&gt;
  </code></pre>
  
  <p>I want users to download a file when they click this button. For that, I'm using the following Ajax request:</p>
  
  <pre><code>$parent.find('button[name=download]').click(function () {
      $.ajax({
          url: "download.php",
          sucess: function(data, status, jqXHR){
              $console.text('Download efetuado');
          },
          error:function(xhr, status, error){
              $console.text(xhr.responseText);
          }
      });
  });
  </code></pre>
  
  <p>Where download.php is:</p>
  
  <pre><code>if (file_exists($myFile)){
          header ("Content-Type: application/json");
          header ("Content-Disposition: attachment; filename=$fileName");
          header("Content-Length: " . filesize("$myFile"));
          $fp = fopen("$myFile", "r");
          fpassthru($fp);
      } else {
          echo "no file exists";
      }; 
  </code></pre>
  
  <p>This isn't outputing anything and no file is downloaded. I know the PHP script is working and is being called.</p>