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

  • SEARCH
  • Home
  • 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 9295117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:31:47+00:00 2026-06-18T21:31:47+00:00

Basically I would like to have a button that people could click to export

  • 0

Basically I would like to have a button that people could click to export some data. Currently I have this hooked up to an ajax call that hits some code I have on the server to get the data. Unfortunately the user is never prompted to save a file or anything, the call is just successfully made.

If I look at the response to the ajax call it has the JSON that I want to export in it. Here is the code I have come up with so far:

#exportData is just a function that gets data based off of a surveyId
@exportData req.body.surveyId, (data) ->
    res.attachment('export.json')
    res.end(JSON.stringify(data),'UTF-8')

Any suggestions to get this to prompt the user to save the file rather than just quietly returning the data?

  • 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-18T21:31:48+00:00Added an answer on June 18, 2026 at 9:31 pm

    I wrote a demo app to play with this a bit:

    app.js:

    var express = require('express')
      , http = require('http')
      , path = require('path')
      , fs = require('fs')
    
    var app = express();
    
    var data = JSON.parse(fs.readFileSync('hello.json'), 'utf8')
    
    app.get('/hello.json', function(req, res) {
      res.attachment('hello.json')
      //following line is not necessary, just experimenting
      res.setHeader('Content-Type', 'application/octet-stream')
      res.end(JSON.stringify(data, null, 2), 'utf8')
    })
    
    http.createServer(app).listen(3000, function(){
      console.log('Listening...')
    });
    

    hello.json:

    {
      "food": "pizza",
      "cost": "$10"
    }
    

    With just HTTP headers, I believe this is just browser specific. Essentially, what’s going on is the res.attachment function is setting the Content-Disposition HTTP server header to attachment. Some browsers such as Firefox prompt you to “Save As”. Chrome and Safari don’t by default. However, you can change this default behavior in the options of either Chrome or Safari. I did not test in Internet Explorer.

    I tried changing the Content-Type to see if that would override any behavior, but it doesn’t.

    In short, you’re not going to be able to overwrite your users’ settings.

    You can see more here: How to force a Save As dialog when streaming a PDF attachment

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

Sidebar

Related Questions

Basically what i would like to do is have a button which is only
Basically I would like to have the user click in the text field and
I would like to have fuzzy looking border around my Canvas control. Basically, I
Basically i have a classic vhost with: ServerName www.site.com ServerAlias site.com I would like
I would like to add a preprocessor to HTML pages. Basically, I have a
I would just like your feedback on something. Basically I have a value called
I would like to basically get all the events that i get invited to
I would like to create a custom data type which basically behaves like an
I have a button set, and would like to set the width of each
I have a button that uses a stretchable PNG as the background image, like

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.