Link to home
Start Free TrialLog in
Avatar of cofactor

asked on

want to get download prompt

Here is the Jquery request sent to MyAction class

                  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"
response.setHeader("Content-disposition","attachment; filename=abc.doc;");
// blah
// blah
Avatar of adeelshahid

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cofactor


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 ?

comments please.
Avatar of Sathish David  Kumar N
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 )
>>>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
>>>>>>success: function(result){
here u can call the jsp like form submit
so this will go to ur actoion calss there you can redirected to another JSp .
>>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 .
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() {
			var ifi=0;
			var container = document.getElementById('mainAction');
			container.innerHTML+='<iframe id="ifi'+ ifi +'" height="55" frameborder="1" width="55" name="ifi'+ifi+'"></iframe>';
			document.forms[0].target = 'ifi' + ifi ;


		<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 ?
I have used Iframe and have a tweak  in my code . problem resolved.
I had a couple of tweaks but this comment helped