troubleshooting Question

Kick off file download with XHR request

Avatar of derekl
derekl asked on
JavaScriptWeb Browsers
1 Comment1 Solution332 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Romi Kuntsman
Big Data Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros