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

  • Home
  • SEARCH
  • 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 5932265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:48:37+00:00 2026-05-22T14:48:37+00:00

I use AJAX POST to send form data to an external script and attempting

  • 0

I use AJAX POST to send form data to an external script and attempting to hide the form on submit and prompt the user to download the script.

The script itself works well (uses fpdf to output pdf file for download). For some reason, prompting the user to download though never comes through.

My Ajax request is currently:

        $.ajax({
            url: "file.php",
            type: "POST",
            data: data,
            cache: false,
            success: function (html) {
                //hide the form
                $('#form').fadeOut('slow');

                //display results
                $('#form_results').fadeIn('slow');
                $("#form_results").html(html);
            }       
        });

file.php (on it own) will generate and display a PDF using FPDF. By setting the Output to I, the document is output to a browser, setting to ‘D’, it would normally force a download if I were simply accessing file.php directly.

any ideas?

  • 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-22T14:48:38+00:00Added an answer on May 22, 2026 at 2:48 pm

    Unfortunately you can’t force a download directly from an ajax call. Your best bet is to submit the form through ajax and have ajax respond with a url that you can redirect the user to that starts the download. However, just an FYI, using location.href to a page that sends a header to force download in IE will cause the yellow security bar to appear on the top of the page. This happens in IE8, not sure about other versions. FF and Chrome don’t have a problem with it.

    Edit:

    Just wanted to add, when you do redirect someone to a page that forces download, they don’t actually leave the page they currently are on. So they won’t have to reload an ajax page or anything. The download dialog will just show up. So if you are on index.php and you say location.href=’download.php’ and download.php forces a download. You just get the download dialog and don’t leave index.php.

    Edit2:

    there are actually quite a few questions about this already.

    https://stackoverflow.com/search?q=force+download+over+ajax

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

Sidebar

Related Questions

How do i use ajax to send POST requests to the server instead of
I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method
A form, I use AJAX to transfer the data. The AJAX is triggered by
I use Ajax (jQuery) and the POST method to update data in the database.
I am trying to use a form to send an prototype ajax request to
I'm using jQuery.ajax to extract form data from a page, and send it to
I have the following Ajax call which send form data to a page and
I have many forms that use AJAX (w/ jQuery) for validation and data submission.
I would like to post a form using ajax and jquery to a .asmx
Is it possible to send form data to a PHP class' method rather than

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.