javascript - Content-Disposition:attachment not triggering download dialog -


I had to face some unexpected behavior while trying to create file download functionality on my NodesJS server. I have a space (API) API that calls for some export data function, which creates a CSV file on the server and res.download ('path / to / file') to trigger the download. . Response headers include

  Content-dispute: attachment; Filename = "indicators.csv" Content-Length: 30125 Content-Type: Text / CSV; Charset = UTF-8  

So everything is in order.

The thing is, I get a response from the server as plain text. In response, all the data present in the CSV file, but the browser file download dialog does not trigger as I wanted. I tried both on Chrome and FF

Update

I managed to work on creating a dummy form, and to make my AJAX call Using your submission but this is an ugly hack, and I'm still looking for a more elegant solution.

No headers are problematic. The problem is that you are asking the download URL through an AJAX call, which will not open the browser download dialog. Boil your options for the following:

  1. Use a form that has been submitted to your download URL. Instead of creating a form with javascript , create a view form instead of the user form.submit -

  2. Point window.location on the download URL. You can do it in the current window, - or newer -


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -