Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

want to get download prompt

Posted on 2011-03-07
11
Medium Priority
?
525 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 1500 total points
ID: 35056576
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
ID: 35059322
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
ID: 35063595
comments please.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35068177
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
ID: 35082068
>>>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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35082097
>>>>>>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
ID: 35082170
>>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
ID: 35082262
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
ID: 35092281
I have used Iframe and have a tweak  in my code . problem resolved.
0
 

Author Closing Comment

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

Expert Comment

by:Sathish David Kumar N
ID: 35092372
Gd....
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

783 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