Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:41:19+00:00 2026-06-10T02:41:19+00:00

EDIT From what I have learned (from comments by nico_ekito) it is not possible

  • 0

EDIT

From what I have learned (from comments by nico_ekito) it is not possible to use ajax call to download a file. The solution is to create a hidden <iframe> that will download the file, described here.


Problem:
The browser doesn’t show download dialog. Any browser – ff, opera, chrome, safari, ie.

I read the docs about serving files, found this question and, based on this, wrote:

Controller.response().setContentType("text/csv");
Controller.response().setHeader("Content-Disposition", "attachment;filename=public/export/filename.csv");
Controller.response().setHeader("Cache-control", "private");

return ok(CSV.export(data, filename));

Where CSV is a class:

public class CSV{
    public static File export(Map<String, String> data, String filename){
        String csv = data.get("data[saveMe]");

        try {
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("public/export/" + filename), "UTF-8"));
            bw.write(csv);
            bw.newLine();
            bw.flush();
            bw.close();
        }catch(UnsupportedEncodingException e){}
        catch(FileNotFoundException e){}
        catch(IOException e){}

        File downloadMe = new File("public/export/" + filename);

        return downloadMe;
    }
}

On client side, I use dojo to send POST request (I also tried with GET, result is the same):

xhr.post({
    url: '/exportData/',
    content: {
        saveMe: str
    }
}).then(function(response){
    //do sth 
});

Response headers look like that:

Cache-Control       private
Content-Disposition attachment;filename=public/export/filename.csv
Content-Type        text/csv
Transfer-Encoding   chunked

POST tab in firebug shows proper data in proper csv format. To format data with csv style I use dojox/grid/enhanced/plugins/exporter/CSVWriter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:41:21+00:00Added an answer on June 10, 2026 at 2:41 am

    I think it is not possible to download a file from an Ajax request, see this question: Allow User to Download File using Ajax

    You should either use an iframe as suggested in the question, or use a standard HTML form containing your data, and do a post on this form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Knockout observable array that I wish to edit from within Javascript
I have this function to edit all fields that come from the form and
I have an edit form, where the values are populated from the database. I
FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
I have a controller in MVC serving up images from a database. EDIT: This
how does one use code to do this: produce 15 random numbers [EDIT: from
I want to edit .vimrc file from Vim and apply them without restarting Vim.
i have made a file open dialog, it contains an edit control whose variable
I learned from this article that to avoid confliction between javascript libraries, use jQuery.noConflict();
char *p=orkut vs const char *p=orkut whats the difference btwn these two... EDIT from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.