Using the HTTP Accept Header from JavaScript
<ul>
<li>I have a web service that performs a database search.  It accepts both GET and POST requests, and can return data in either JSON, CSV, or HTML format based on the HTTP <code>Accept</code> header.</li>
<li>I have a web page that makes an Ajax request to this web service, and displays the search results.</li>
<li>I have been asked to add a button to this page that will allow the user to save the data in CSV format.</li>
</ul>

<p>Earlier this year, someone was <a href="http://stackoverflow.com/questions/2515162/need-to-save-html-table-to-csv-using-javascript">in the same boat</a>, and got the response</p>

<blockquote>
  <p>You cannot do it using javascript
  capabilities, since javascript has no
  permission to write on client machine,
  instead you can send request to server
  to create csv file and send it back to
  client.</p>
</blockquote>

<p>So I added a button that does</p>

<p><code>window.open("MyWebService.cgi?" + theSameQueryStringIPassedInTheAjaxCall)</code>,</p>

<p>which opens the HTML version in a new browser tab.  I want the CSV version.  Is there a way I could pass an <code>Accept: text/csv</code> HTTP header?  (I know how to do it with XMLHttpRequest and setRequestHeader, but that doesn't help me.)</p>
