title: How do I get jQuery $.ajax to download an XLSX document?
body: <p>I currently have this markup with two links and I'm trying to have both called via AJAX.</p>
  
  <p>I have a search which runs a query based on the start and end date used, and I have an export to Excel link that I'm trying to have download an Excel document with the start and end date used.</p>
  
  <p>Everything works fine except for getting the <code>#export</code> <code>$.ajax</code> call to download the Excel document. </p>
  
  <p>How can I get jQuery to download an Excel document?</p>
  
  <pre><code>&lt;a href="#" class="buttonH bBlue" id="export"&gt;Export to Excel&lt;/a&gt;
  &lt;a href="#" class="buttonH bBlue" id="search"&gt;Search&lt;/a&gt;
  &lt;div class="headInput" id="reportsDateSearch"&gt;
      &lt;input type="text" name="start_date" placeholder="&lt;%= @end_date %&gt;" class="datepicker" id="endDate" /&gt;
      &lt;input type="text" name="end_date" placeholder="&lt;%= @start_date %&gt;" class="datepicker" id="startDate" /&gt;            
  &lt;/div&gt;
  </code></pre>
  
  <p>jQuery AJAX calls:</p>
  
  <pre><code>// This call gets the data based on the start and end date used
      $('#search').on('click', function() {
          $.ajax({
              type: "GET",
              beforeSend: function(xhr) { 
                  xhr.setRequestHeader("Accept", "text/javascript");
              },
              url: '&lt;%= reports_affirmative_action_path %&gt;',
              data: {start_date: $('#startDate').val(), end_date: $('#endDate').val()}
          }, null, 'script');
      });
  
  
  // This call gets the data based on the start and end date used, but i'm trying to get it to return the xlsx format.
      $('#export').on('click', function() {
          $.ajax({
                  type: "GET",
                  beforeSend: function(xhr) { 
                      xhr.setRequestHeader("Accept", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                  },
                  url: '&lt;%= reports_affirmative_action_path(:format =&gt; :xlsx) %&gt;',
                  data: {start_date: $('#startDate').val(), end_date: $('#endDate').val()}
          }, null, 'script');
      });
  </code></pre>