1

To download file I am using ajax. I have three status:

"Download file" - before you click on the link. "File is downloading..." - while the file is downloading "Download file" - if the file was generated successful "Error while downloading file" - if there was any error while download the file. 

I'm using JSP, jquery ajax. How to determinate that there was an error with downloading the file with using ajax or the download was successfull.

3
  • download file how exactly? Post the code you have! Commented Jul 29, 2013 at 10:43
  • The browser does that anyway, why do you want to implement it a second time? Commented Jul 29, 2013 at 10:49
  • just call a servlet wich write the file in the response Commented Jul 29, 2013 at 11:02

1 Answer 1

4

You cannot download a file using ajax, and make it useful. Ajax response is loaded into javascript memory. Javascript dont have disk access to save that file.

So better do it in normal way using header "content-type" Content-Disposition: attachment; filename="file name.ext" using normal request.

This will download file and browser will provide user an option to save file. Also note that this wont reload your page.

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

3 Comments

the ajax call a url with parameters which is servlet which generate the document and write it in the response. The problem here is that ajax receive the response as message.
Javascript will receive the file data in $ajax.response, but it cant do much with it.
I did it with iframe but in that case I have two requests to the server.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.