title: Download a pdf using ajax and spring mvc doesn't work
body: <p>I'm trying to implement an ajax download. This is my code for the ajax request:</p>
  
  <pre><code>$('#download').click(function(){
                      $.ajax({  
                          url: '${downloadPath}',  
                          type: 'GET',  
                          data: {${_csrf.parameterName}:'${_csrf.token}'},  
                          success: function (res) {  
                          }
                      });
                  });
  </code></pre>
  
  <p>And this is my controller's method:</p>
  
  <pre><code>    @Secured("IS_AUTHENTICATED")
      @RequestMapping(value="download/{id}", method=RequestMethod.GET, produces="application/pdf")
      @ResponseBody
      public void download(@PathVariable(value="id") final Long id, HttpServletResponse response) throws IOException {
  
          CheckList checkList = checkListService.findById(id);
  //      byte[] byteItem  = checkListService.getFileByIdDocument(id);
  
          File f = new File(VariabiliGlobali.PATH_CHECKLIST+checkList.getPratica().getId()+"/"+id);
          ServletOutputStream out = response.getOutputStream();
  
          response.setContentType("application/pdf");
          response.setContentLength((int)f.length());
          response.setHeader("Content-Disposition", "attachment; filename=\"" + f.getName() + "\"");
  
          FileInputStream in = new FileInputStream(f);
          byte[] buffer = new byte[4096];
  
          int length;
          while( (length = in.read(buffer) ) &gt; 0) {
              out.write(buffer, 0, length);
          }
          in.close();
          out.flush();   
      }
  </code></pre>
  
  <p>I can see the pdf inside the response:</p>
  
  <p><a href="https://i.stack.imgur.com/WxQ7W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WxQ7W.png" alt="enter image description here"></a></p>
  
  <p>But my browser (Chrome) doens't do anything.</p>
  
  <p>Where am I wrong? How can I dowload it?</p>