-1

I wanted to create a hyperlink, which on clicking should downloaded a csv file based on the parameters and trigger an action . I implemented it as:

<a href="../csvcontroller/csv" class="export">2001</a> 

It doesn't seem to work. Can anyone advice me the right way of doing it?

Kailas
  • 7,350
  • 3
  • 47
  • 63
preeti
  • 11
  • 1
  • 6
  • Define "not working". – Raptor Jan 08 '15 at 07:07
  • 1
    https://stackoverflow.com/questions/17836273/export-javascript-data-to-csv-file-without-server-interaction – Paul Jan 08 '15 at 07:09
  • Possible duplicate of [How to trigger a file download when clicking an html button or javascript](http://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript) – Ani Menon Jul 26 '16 at 09:24

2 Answers2

0

you did not put the extention of file! you should put dot(.) after the name of file like < a href="../csvcontroller/example.csv" class="export" >2001 < /a>

asim
  • 103
  • 1
  • 8
0

You did not specify whether or not CSV has to be created on fly, or You have some pre-made CSV files stored on the server and You want to download specific file based on some condition on client side. Some more information would definitely help.

For dynamic CSV creation and download here's a PHP article showing how to achieve it (concepts can be transfered to other server side languages as well) >> Creating downloadable CSV files using PHP

For pre-made CSV files You can generate file link dynamically and call it using client side JavaScript:

var userName = "dan"

if(userName === "dan")
{
    window.open("http://sitename.com/dan.csv","_self")
}

else if (userName === "mark")
{
    window.open("http://sitename.com/mark.csv","_self")
}
Maz T
  • 1,184
  • 13
  • 18