Solved

want to get download prompt

Posted on 2011-03-07
11
523 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 
LVL 2

Accepted Solution

by:
adeelshahid earned 500 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

617 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