title: How to use AJAX to download files without page referesh in Octobercms?
body: <p>I am new to laravel and october cms. I want to add a button to allow users download a PDF file, 'a.pdf', without directing to a new page. I know that I have to use AJAX and send a download http response in order to make browsers show a 'Save As...' dialog box. So far this is what I have accomplished:</p>
  
  <pre><code>title = "Sandbox"
  url = "/test"
  layout = "default"
  ==
  &lt;?php
  function onDownload()
  {
      $pathToFile = Url::to("/storage/app/media/a.pdf");
      $fileName = "download.pdf";
      $headers = [
          'HTTP/1.1 200 OK',
          'Pragma: public',
          'Content-Type: application/pdf'
      ];
      return Response::download($pathToFile, $fileName, $headers);
  }
  ?&gt;
  ==
  &lt;div class="container"&gt;
      &lt;form class="form-inline" data-request="onDownload"&gt;
          &lt;button type="submit" class="btn btn-primary" data-attach-loading&gt;Download&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I get "The file "<a href="http://localhost/october/storage/app/media/a.pdf" rel="nofollow noreferrer">http://localhost/october/storage/app/media/a.pdf</a>" does not exist" error using above code.</p>
  
  <p>What am I doing wrong?</p>