?
Solved

Download to CSV file jquery

Posted on 2014-01-29
3
Medium Priority
?
765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

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 43

Accepted Solution

by:
Chris Stanyon earned 2000 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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)
Suggested Courses

771 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