1
  • 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 Accept header.
  • I have a web page that makes an Ajax request to this web service, and displays the search results.
  • I have been asked to add a button to this page that will allow the user to save the data in CSV format.

Earlier this year, someone was in the same boat, and got the response

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.

So I added a button that does

window.open("MyWebService.cgi?" + theSameQueryStringIPassedInTheAjaxCall),

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

2
  • 1
    Wouldn't it be easier to add a parameter to the querystring? (e.g. format=csv) Commented Sep 1, 2010 at 19:43
  • 1
    I'd prefer not to reimplement something that's part of the HTTP protocol. But I could easily do that if I have to. Commented Sep 1, 2010 at 19:52

1 Answer 1

1

Don't think so. I think you should use an parameter instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.