0
  1. Client (Request through XMLHttpRequest) -> Server.
  2. Server [Builds CSV and prints it on the output stream of response] -> Client.

Now step 3 should be-> Client's browser should show a download dialogue (save, open and cancel). Since the content type is plain text from the server, and the content disposition is not set, can we create a file using javascript and prompt the user to download?

I know this question is slight stupid. But there is no other option. I have to do it this way.

Changing in the server side script will make it a one minute task. But I have to do it in the client side. The responseText property of the XMLHttpRequest object will be plain text and I have to show download prompt for the text file.

Is this possible?

2 Answers 2

1

Not that I'm aware of. But you could just use location.href (or a form, if POST data is needed) to request the server-side file. With the correct headers (Content-Disposition: attachment and I think there's another one) you can have the response be downloaded rather than displayed.

EDIT: Even better, use an iframe that's hidden. That way, you can still do a fancy "Loading, please wait" thing in the main page.

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

Comments

1

Theoretically it could be possible, by using Data URI's

<a download = "yourfile.csv" href="data:application/octet-stream;charset=YOURCHARSET;base64,BASE64allthedata">Generate</a>

1 Comment

Sir is it actually implemented in HTML 5 and not in lower versions ? (I mean download attribute of <a>). Thanks for the reply.

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.