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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:34:16+00:00 2026-05-18T08:34:16+00:00

im trying to have one link for a file download and at the same

  • 0

im trying to have one link for a file download and at the same time submit a post form over ajax.
kinda looks like this:

<form action="" method="post" id="form">
    <input type="text" name="email" id="email" value="" />
    <input type="hidden" name="subscriber" id="subscriber" value="newsletter" />
    <a href="/files/application.exe" id="download">trial download</a>
</form>
<script type="text/javascript" src="jquery"></script>
<script type="text/javascript">
    // prevent default submit action caused by enter key etc.
    $("#form").bind('submit',function(event){event.preventDefault();});
    $('#download').click(function(){
        $.post(location.href, $('#form').serialize(), function(){
             $('#form').hide();
        });
    });
</script>

problem is that the download fires and it shows the download dialog – which is correct – it also fires the click event and would even console log inside the click event function, it on top even fires the post request but the post request never ends up at the server. i had the access log file on tail -f and it only shows the GET on the application.exe but no POST from the $.post(). in firebug it shows the POST http://ip/folder/ given by the location.href and its marked in red with a little X and an empty response field. tough for firebug it looks like it got sent to the server…

my explanation for this is that the href takes the wind out of the $.post() and before it gets fired it redirects the browser to the download file. doesnt change the page itself but stops the action of posting over XHR…

does anyone know a good workaround for this? i really need the native href link to the application to not cause IE to bring up this stupid file download warning bar and at the same time i need the ajax to submit the form…

thanks!

  • 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-18T08:34:16+00:00Added an answer on May 18, 2026 at 8:34 am

    Refactor as follows, returning false to prevent the default link click behavior:

    $('#download').click(function(){
        var href = $(this).attr('href');
        $.post(location.href, $('#form').serialize(), function(){
             $('#form').hide();
             document.location.href= href;
        });
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have two submit buttons in my form - one accepts
I have one .net windows application I'm trying to read .xml file from c#
I have a page with several forms. I am trying to submit one of
I have one question, I was trying to find more information on the internet
I have one user (only one, all the others are fine) trying to update
I want to have one callback function after actions are done, I'm trying something
Trying to make simple minesweeper game in python, but have one problem. I have
I'm trying to get rid of floats in my functions. I have one function
I am trying to set support information on machines with C#. I have one
I am trying to have an h:inputText switch out with a different one when

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.