title: Getting file from .ashx with a jQuery Post
body: <p>This question is a following from another question I asked - <a href="https://stackoverflow.com/questions/8788861/passing-client-data-to-server-to-create-excel-or-csv-file">Passing client data to server to create Excel or CSV File</a>.</p>
  
  <p>I have a client page which builds a JSON object to send to the server, and I have server code which can parse that JSON object into an SQL command and end up with a dataset of required data.</p>
  
  <p>I had originally been passing the JSON object to an .asmx web service which would return a JSON object containing my data. Now I want to go in a different direction and have the data returned as a .csv file.</p>
  
  <p>I understand I can try to put my JSON object into a query string and call my .ashx page, but the JSON object could get large, so I'm trying to use the Request.Form of a POST.</p>
  
  <p>My question, and lack of understanding, is in how to use jQuery to post to the .ashx page and have it return the .csv file to the client. If I navigate to the .ashx page directly (and modify the page to hard code the passed data), I get the .csv file returned to me no problem (i.e I get the prompt to open/save the file). If I make a POST to the .ashx file from jQuery and send my JSON object through, I get a response which contains the data in a string, rather than getting a .csv.</p>
  
  <p>So, is there something I am missing, or am I just trying to achieve something that I can't or shouldn't be doing?</p>
  
  <p>I'd thought about passing my JSON object to a .asmx web service which would store the JSON object into a database and return an ID, and then use window.location to browse to the .ashx with the ID as a query string parameter to then generate the .csv file, but I thought there might be a way to avoid that middle step and do it with the POST.</p>
  
  <p>Sorry if this is a little rambling and disjointed. I'll be happy to clarify on any parts that may not make sense to anyone.</p>