Avatar of derekl
derekl
 asked on

Kick off file download with XHR request

I'm writing a fairly complex web application that needs to support the download of data in CSV format.  I already have a servlet I can query which expects a POST request with JSON in the body describing the data that I want that returns JSON data in response to an XMLHttpRequest.

What I would like to do is duplicate that XmlHttpRequest (against a different servlet URL) which returns the same data in CSV format and would cause the save file dialog to open.

My fear is that the browsers normal response to a "text/plain" MIME type will be suppressed by virtue of the fact that the request originated with XmlHttpRequest.

Is there any way to do what I need?

Another way to do this would be to create an arbitrary POST request (with JSON data as the body) and redirect the browser to it, but I have no idea how to do this.

I'm lucky in that this is a Firefox only app so solutions need not be portable.  Thanks in advance.

Derek
Web BrowsersJavaScript

Avatar of undefined
Last Comment
Romi Kuntsman

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Romi Kuntsman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck