Solved

Download to CSV file jquery

Posted on 2014-01-29
3
731 Views
Last Modified: 2014-02-04
Hello,
  I have data in an HTML table. I would like to read the data in the table and download it in a CSV format .

Basically, the table has a check box. name and address and download button. When the download button is press I would like to read the data in the selected row and force an http download of the file.  

Thanks for your help
0
Comment
Question by:SiemensSEN
  • 2
3 Comments
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39817778
You can't do this with javascript - you would need to use a server-side script, such as PHP.

When the download button is pressed, you would need to send your data, using Javascript / AJAX to a script on the server. That script would create the file, and then send back any info (filename /path etc.) back into Javascript, where you could then handle it however you like
0
 

Author Comment

by:SiemensSEN
ID: 39817791
Ok,

So, the procedure is:

JavaScript
-- Loop thru the table
-- construct a CSV string
-- use ajax and pass the CSV string to the server script

Server
-- Create a file with CSVString content
-- then force the HTTP download.

Thanks
0
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39817836
Yeah, pretty much, although you say you only want to send the selected row, so there should be no need to loop through the table.

You'll probably also find it easier to build the CSV string on the server-side. I know PHP has some useful CSV functions, such as fputcsv() - it takes a file pointer and an array, converts the array into a CSV string and writes it to a file - easy :)

In that case you'd just pass your individual values to the server using one of the jQuery ajax functions - ajax(), post() etc.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now