Download a file by jQuery Ajax

0 votes

I have a Struts2 action in the server side for file downloading.

<action name="download" class="com.xxx.DownAction">
    <result name="success" type="stream">
        <param name="contentType">text/plain</param>
        <param name="inputName">imageStream</param>
        <param name="contentDisposition">attachment;filename={fileName}</param>
        <param name="bufferSize">1024</param>
    </result>
</action>

However when I call the action using the jQuery:

$.post(
  "/download.action",{
    para1:value1,
    para2:value2
    ....
  },function(data){
      console.info(data);
   }
);

in Firebug I see the data is retrieved with the Binary stream. I wonder how to open the file downloading window with which the user can save the file locally?

May 27 in JQuery by Edureka
• 13,640 points
168 views

1 answer to this question.

0 votes

Downloading files using AJAX method

  1. $("#FileDownloadBtn"). click(function () {
  2. event. preventDefault();
  3. var rootPath = '@Url.Content("~")';
  4. $. ajax({
  5. type: "post",
  6. url: rootpath + "/RequestFormEdit? handler=FileDownload",
  7. success: function (data) {
  8. }
answered Jun 10 by gaurav
• 17,760 points

Related Questions In JQuery

0 votes
1 answer

Download File Using JavaScript/jQuery

Suppose you want to download a file ...READ MORE

answered Jun 3 in JQuery by Edureka
• 13,640 points
293 views
0 votes
1 answer

Download File Using JavaScript/jQuery

<!DOCTYPE html> <html> <head> <title> Download File Using JavaScript/jQuery </title> </head> <body> <h1> Download File Using JavaScript/jQuery </h1> <a id="link" ...READ MORE

answered Jun 10 in JQuery by rajatha
• 7,040 points
74 views
0 votes
1 answer

How to check if a jQuery plugin is loaded?

Hello @kartik, for the plugins that doesn't use ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,740 points
749 views
0 votes
1 answer

How do I pre-populate a jQuery Datepicker textbox with today's date?

Hello @kartik, You must FIRST call datepicker() > then use ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,740 points
5,665 views
0 votes
1 answer

How to refresh a jQuery UI Slider after setting min or max values?

Hello @kartik, You should try doing something like ...READ MORE

answered May 30, 2020 in JQuery by Niroj
• 82,740 points
3,193 views
0 votes
1 answer

How can I refresh a page with jQuery?

Hello @kartik, Use location.reload(): $('#something').click(function() { location.reload(); }); The reload() function ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,740 points
260 views
0 votes
1 answer

How to scroll to element from bottom to top with a nice animation using Jquery?

Hello @kartik, Assuming you have a button with ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,740 points
2,647 views
0 votes
1 answer

How do I iterate through children elements of a div using jQuery?

Hello @kartik, Use children() and each(), you can optionally pass a ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,740 points
2,721 views
0 votes
1 answer

Download pdf file using jquery ajax

Download PDF file with button click using ...READ MORE

answered May 30 in JQuery by gaurav
• 17,760 points
1,493 views
0 votes
1 answer

Download File Using JavaScript/jQuery

Download Files Create a DOMString that contains the ...READ MORE

answered Jun 10 in JQuery by gaurav
• 17,760 points
318 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP