0

I have a JAX-RS webservice that creates an excel file as a byte array and returns it to my javascript application, the service works as I can inspect the response with firebug and it contains the headers I set and the bytes containing the excel file.

However I thought by setting the content-disposition header there would be a save dialog, seems not.
Below I've pasted the headers I'm getting in my response, is there anything I forgot?

Content-Disposition attachment; filename=file.xls
Content-Length  17920
Content-Type    application/vnd.ms-excel
Date    Thu, 10 Jan 2013 07:07:49 GMT
Server  Apache-Coyote/1.1
X-Powered-By    Servlet 2.5; JBoss-5.0/JBossWeb-2.1

The ajax call currently doesn't have a success function, do I need to write some kind of function to show the save dialog or is it sufficient that I set additional headers, if so which ones?

Thanks
J.

3
  • 1
    Instead of using ajax just do a window.location.href = 'path/to/xlsfile/';
    – Musa
    Jan 10, 2013 at 7:19
  • there is no actual path to the excel it's never saved to disc, is there another way?
    – J.Pip
    Jan 10, 2013 at 7:22
  • Its the same request url used in the ajax request, if the ajax request is a post request then use a form and post it to an invisible iframe.
    – Musa
    Jan 10, 2013 at 7:25

2 Answers 2

0

As suggested by Musa above, get rid of AJAX and just forward your user to the URL which returns Excel data with exactly the headers you use now (they are correct).

0

This is how I fixed it:

I kept the ajax call because I'm sending a lot of parameters and arrays of data in a specified json format to the server side, however I returned a base64encoded string which I added to a hidden form which pointed to a link on the server side which sets the headers in a response with the decoded string, not the most elegant solution but it does the trick

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.