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 649483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:56:56+00:00 2026-05-13T21:56:56+00:00

I have a script for exporting results of a mysql query as a csv

  • 0

I have a script for exporting results of a mysql query as a csv file. The thing is that i use jquery to access the script. I need to know how i can return the data (already in csv format) with jquery. In other words, just to make myself clear because my english is a bit poor, when the user presses a button in the html file, a post request is sent to a php file which returns the data in csv format. I want to take that data with jquery and serve the .csv file to the user.

PHP file:

<?php
    session_start();
    header ("Content-type: application/csv\nContent-Disposition: \"inline; filename=my.csv\"");
    include("config.php");
    $query = $_SESSION['sqlQuery'];

    $result = mysql_query($query) or die("Query failed : " . mysql_error());
    echo "ID,STATUS,CATEGORY,TITLE,DATE,URL\r\n"; //header
    while($row = mysql_fetch_row($result)) {
        echo "$row[0],$row[4],$row[3],$row[1],$row[2]\r\n"; //data
    }
?>

I need something in the HTML like:

$("#exportToCsv").click(function(){
   $.post("export.php",function(data){
        here the code for exporting much like downloading a file
  });
});
  • 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-05-13T21:56:56+00:00Added an answer on May 13, 2026 at 9:56 pm

    You can just link to the file (no ajax, no $.post) with the header henchman said. It will download the file. Ajax is ment for javascript to get the file, not to perfom download.

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

Sidebar

Related Questions

I have a jquery script that searches a php file that produces an XML
I have script that reads remote file content and writes it to local server.
I need to have script.sh , that would create files f1.txt and f2.txt with
I have an issue with exporting BLOB to a csv file using php. Obviously
I have script file where a command is stored in a variable First i
I have script which allows to display Bing search results. I can call for
I have this script that run to fix my menu bar to the browser
I have an script interpreter that is spawn by a deamon and has to
I have a Unix bash function that executes a script that parses custom environment
I have been doing some customization to this jQuery paging script I found here

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.