Hi,

Can you help me with the following problem?

I have a form where you select the parameters to generate a PDF report that will be returned by a Struts 1.x action that will be opened by the browser. This is working perfectly synchronously in the system.

But what I need to protect the system from the user is requesting the report without having done all the time, putting a lock on the button to be enabled only once the report was generated.

My choice was to create a function in AJAX (asynchronous call) to which this report was generated, and while this process does not answer me back I hide the button and show the "loading" and so has the return button I show and hide the "loading".

But I'm having problems in two different trials:

In the first attempt (code 1) with jQuery behavior of the button and the loading are expected but my PDF file that returns the function (data) below does not open in browser download window:

...
success: function (data) {
WinID var = window.open ('', 'newwin', 'width = 400, height = 500');
WinId.document.open ();
WinId.document.write (data);
WinId.document.close ();
...

On the second try (code 2) using Dojo return the PDF file is expected but when the browser's download window opens lose control in order to enable the button again and disable image loading.


Is there any way to open this PDF file using jQuery or Dojo in control my DIVs?


Thank you,


HTML Fragment:
...
<tr>
<td colspan="3" align="center" valign="middle">
<div id="button">
<a href="javascript:execute();">
<img src="images/btnExecute.png" alt="Execute" border="0" class="inputImage" />
</a>
</div>
<div id="loadingImage">
<img src='images/loading.gif' style="{align:right;}" />
</div>
</td>
</tr>
...


Code 1 (jQuery):

function execute()
{
$.ajax({
type:"GET",
url: "generateReport.do",
data: "action=print&param1=param1",
dataType: "html",
beforeSend : function() {
//It works
$('#button').hide();
$('#loadingImage').show();
},
complete : function() {
$('#button').show();
$('#loadingImage').hide();
},
success : function(data) {
var WinId = window.open('', 'newwin', 'width=400,height=500');
WinId.document.open();
WinId.document.write(data);
WinId.document.close();
}
});
}

Code 2 (Dojo):

function execute()
{
//It works
$('#button').hide();
$('#loadingImage').show();

var url = "generateReport.do?action=print&param1=param1";

require(["dojo/io/iframe"], function(ioIframe){
ioIframe.send({
url: url,
handleAs: "html"
}).then(function(data){
//It only works when my page returns the html message "Empty report"
$('#button').show();
$('#loadingImage').hide();
}, function(err){
});
});
}