Solved

want to get download prompt

Posted on 2011-03-07
11
519 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
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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

828 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