Solved

want to get download prompt

Posted on 2011-03-07
11
513 Views
Last Modified: 2012-05-11
Here is the Jquery request sent to MyAction class

$.ajax({
                  type: "POST",
                  url: "MyAction",
                  data:  $('form').serialize(),
                  cache: false,
                  dataType: "html",
                  success: function(result){
                  
                   // what to write here so that I can get doc download prompt
               
                }
 });
 
 


Struts MyAction  retruns "result.jsp"
      
      
result.jsp
------------
 <%
response.setContentType("application/doc");
response.setHeader("Content-disposition","attachment; filename=abc.doc;");
// blah
// blah
%>
0
Comment
Question by:cofactor
  • 7
  • 3
11 Comments
 
LVL 2

Accepted Solution

by:
adeelshahid earned 500 total points
Comment Utility
You need to submit your request to an iframe that would popup the download prompt.

This requires response header's to be pushed out which shows the download prompt.
0
 

Author Comment

by:cofactor
Comment Utility
I'm doing a JQuery ajax form submit.  Instead of getting a html response , I'm trying to put a download prompt .

Please see the question again . What changes I need to do so that Ajax form submit can pop up a download prompt ?

0
 

Author Comment

by:cofactor
Comment Utility
comments please.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
Do one thing jsut another jsp file in the ajax call that jsp having response.setContentType("application/doc");
response.setHeader("Content-disposition","attachment; filename=abc.doc;");

its show the popup window !! (but you should all the same value in that jsp )
0
 

Author Comment

by:cofactor
Comment Utility
>>>Do one thing jsut another jsp file in the ajax call

how ? how do I do that in my code ?

>>>that jsp having response.setContentType("application/doc");

I have this result.jsp
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
>>>>>>success: function(result){
                 
here u can call the jsp like form submit
document.formName.action="MyAction.html?fetch="+test;
  document.formName.submit();              
                }
so this will go to ur actoion calss there you can redirected to another JSp .
0
 

Author Comment

by:cofactor
Comment Utility
>>here u can call the jsp like form submit

success: function(result)--->This is the result section returned by the action ..why do we call action here ?


Do you mean I need to call the Action here again ? Also I'm doing a JQuery AJAX post submit.

Please see the code again .
0
 

Author Comment

by:cofactor
Comment Utility
I have removed Ajax code and put it other way...I'm using the same result.jsp as my return page when action gets called.

$('#exporttoword').click(function() {
			
			alert("exporttoword");
			document.forms[0].buttonName.value="exporttoword";
			document.forms[0].hdncreatePage.value="3";
		
	        
			var ifi=0;
			var container = document.getElementById('mainAction');
			alert('container='+container);
			container.innerHTML+='<iframe id="ifi'+ ifi +'" height="55" frameborder="1" width="55" name="ifi'+ifi+'"></iframe>';
			document.forms[0].target = 'ifi' + ifi ;
			
			document.forms[0].action="MyAction";
			document.forms[0].submit();


		});



		<input type="button" id="exporttoword" class="submit_btn_base" value="Export to Word"> 

Open in new window



This works ...but issue is , when I click button second time , the click function is not called and so I dont get download prompt on next click.  Can we find a workaround for this ?
0
 

Author Comment

by:cofactor
Comment Utility
I have used Iframe and have a tweak  in my code . problem resolved.
0
 

Author Closing Comment

by:cofactor
Comment Utility
I had a couple of tweaks but this comment helped
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
Gd....
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now