title: Use jQuery to send Excel data using AJAX
body: <p>I have the following function that is pulling data from a database.  The ajax call is working correctly.  How can I send the tab delimited data in my success function to the user?  Setting the contect type to "application/vnd.ms-excel" didn't work.  The alert on success shows the correctly formatted data.</p>
  
  <pre><code>     function SendToExcel() {
         $.ajax({
             type: "GET",
             url: "/Search.aspx",
             contentType: "application/vnd.ms-excel",
             dataType: "text",
             data: "{id: '" + "asdf" + "'}",
             success: function(data) {
                alert(data);
             },
             error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
         }});
       }
  </code></pre>
  
  <p>I don't want to display the data in the browser--I want to send it to Excel.</p>
  
  <p><strong>EDIT:</strong>  I found a way to do what I wanted.  Instead of redirecting the users to a new page that would prompt them to save/open an Excel file, I opened the page inside a hidden iframe.  That way, the users click a button, and they are prompted to save/open an Excel file.  No page redirection.  Is it Ajax?  No, but it solves the real problem I had.</p>
  
  <p>Here's the function I'm calling on the button click:</p>
  
  <pre><code>     function SendToExcel() {
          var dataString = 'type=excel' +
              '&amp;Number=' + $('#txtNumber').val() + 
              '&amp;Reference=' + $('#txtReference').val()
  
          $("#sltCTPick option").each(function (i) {
               dataString = dataString + '&amp;Columns=' + this.value;
          });
  
          top.iExcelHelper.location.href = "/Reports/JobSearchResults.aspx?" + dataString;;
       }
  </code></pre>