0

I have a jQuery ajax form where a user submits his email, once the form has been submitted, the user should get an automated download of a file, the form looks like this:

$(".email-form").submit(function(event) {
    event.preventDefault();

    var $form = $(this),
    form_email = $form.find("input[name='email']").val(),
    url = $form.attr("action");

    var posting = $.post(url, { email: form_email });

    posting.done(function() {
        $(".popup-design").hide();
        $("input[name='email']").val("");
        $("#done").show();
    });
});

and also I need to have to user automatically download a file of my choice when posting is done. How can I do that?

esqew
  • 42,425
  • 27
  • 92
  • 132
Xeen
  • 6,955
  • 16
  • 60
  • 111

1 Answers1

0

You will have to:

  • Create an iframe and add it to your document.
  • Set the iframe's SRC to be a URL to the download.
  • Have the server send the correct headers to cause a download prompt.

Edit - Found this question which is very much related

Using jQuery and iFrame to Download a File

Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74