title: Download file from Ajax (sort of)
body: <p>I have this ajax call in my GSP:</p>
  
  <pre><code>$.ajax({
      url: '${request.contextPath + '/Ticket/passAll'}',
      type: 'POST',
      data: data,
      success: function() {
          alert("Success");
      }
  });
  </code></pre>
  
  <p>This is code block from my controller action:</p>
  
  <pre><code>response.setHeader("Content-disposition", "attachment; filename=sample.csv")
  response.contentType = "application/vnd.ms-excel"
  
  def outs = response.outputStream
  def cols = [:]
  
  tickets.each() {
      outs &lt;&lt; it.ticketNo + ";" + it.subject
      outs &lt;&lt; "\n"
  }
  
  outs.flush()
  outs.close()
  </code></pre>
  
  <p>I get tickets list from data that I pass from view via $.Ajax method. Than I format that data as CSV and than I want to export that data as CSV file but nothing happens. The data is send to client but there is no file for download as content-disposition is not well formed. What am I missing? 
  I've tried to do something like:</p>
  
  <pre><code>$.ajax({
      url: '${request.contextPath + '/Ticket/passAll'}',
      type: 'POST',
      data: aoData,
      dataType: 'text',
      success: function(result) {
          var uri = 'data:application/csv;charset=UTF-8,' + encodeURIComponent(result);
          window.open(uri, 'tiketi.csv');
      }
  });
  </code></pre>
  
  <p>and in controller I generate plain string, but that way I get a file without extension which is unacceptable.  </p>
  
  <p>How can I achieve this? Thank you.</p>