Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Handle file download from Ajax POST

I have a JavaScript application that sends an Ajax POST requests to a certain URL. The response might be a JSON string, or it might be a file (as an attachment). I can easily detect Content-Type and Content-Disposition in my Ajax call, but once I detect that the response contains a file, how do I offer the client to download it? I've read a number of similar questions here, but none of them provide the answer I'm looking for.

Please, please, please do not post answers suggesting that I shouldn't use Ajax for this, or that I should redirect the browser, because none of those is an option. Using a plain HTML form is also not an option. What I do need is to show a download dialog to the client. Can this be done and how?

Answer*

Cancel
1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented Sep 27, 2023 at 1:20