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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:57:01+00:00 2026-06-15T20:57:01+00:00

Possible Duplicate: Downloading Via JQuery AJAX Post not working filedownload.php has below snippent. $file

  • 0

Possible Duplicate:
Downloading Via JQuery AJAX Post not working

filedownload.php has below snippent.

$file = 'cut.png';
header("Content-Type: image/png");
header('Content-Disposition: attachment; filename="'.$file.'"');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
readfile($file);
exit();

AJAX Call

jQuery.post('filedownload.php',{            
  'file'  :  result  // not used for the time being                    
 });

I make an ajax call to the filedownload.php file. It does not allow user to download the file. But If I run the php directly it allows user to download the file. What could be the issue ?

I would like to use core functions rather than using jQuery Plugins. If it’s not possible a plugin would be fine.

Given that I use ajax because the page can not be refreshed.

  • 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-06-15T20:57:03+00:00Added an answer on June 15, 2026 at 8:57 pm

    The Problem

    Let’s take the example of a productivity web app such as a spreadsheet
    editor, which has the ability to open, save, import and export. The
    open and save options would involve loading a spreadsheet from the
    database, whereas import and export deal with local files on the
    user’s machine. To implement the export behavior, you might decide
    that the user should have to save their spreadsheet first, allowing
    you to export the data from the backend to file. But let’s assume
    instead you’d like to allow users to export their data without saving,
    perhaps to afford them the option of working locally without ever
    storing data on the server. In order to do this, you’d need to send
    the current spreadsheet data to the backend and receive a file to
    download. Unfortunately, this can not be handled using Ajax, since
    Ajax can only receive responses in the form of text. In cases where
    the data to be saved is rather lengthy, this poses a considerable
    problem.

    The Workaround

    In order to make the request, you’d need to make a regular (not Ajax)
    HTTP request using GET or POST. If the data is reasonably short, you
    might get away with a GET request (perhaps by simply setting
    Window.location to your export url), but due to varying browser
    limitations on GET request length, a POST will most likely be needed.
    The following plugin allows you to make a request that returns a file
    in a similar syntax to jQuery’s native Ajax functions.

    jQuery Code Which fixes the problem

    jQuery.download = function(url, data, method){
        //url and data options required
        if( url && data ){ 
            //data can be string of parameters or array/object
            data = typeof data == 'string' ? data : jQuery.param(data);
            //split params into form inputs
            var inputs = '';
            jQuery.each(data.split('&'), function(){ 
                var pair = this.split('=');
                inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
            });
            //send request
            jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
            .appendTo('body').submit().remove();
        };
    };
    

    How to call

    $.download('filedownload.php','filename='+filename );
    

    Read more

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

Sidebar

Related Questions

Possible Duplicate: Uploading and downloading via ftp with iPhone SDK I want to implement
Possible Duplicate: How to know the size of a file before downloading it? I
Possible Duplicate: Not able to launch android emulator After downloading Eclipse indigo, and updating
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: caching JavaScript files I'm using JQuery 1.7.2 into JSF page. I call
Possible Duplicates: Downloading a file in Delphi Delphi File Downloader Component Hello everyone, I'm
Possible Duplicate: how to delete a file? My application first reads the fields in
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: In Java: How to zip file from byte[] array? Here's the deal,

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.