A Spring-MVC controller is used to generate a PDF report when a get request is made. The controller includes headers such as "application/OCTET-STREAM", "Content-Disposition", and "attachment; filename=\"" + filename + "\"" in order to prompt the user for save/open action. The controller writes the generated PDF bytes directly to the response's output stream, returning a null ModelAndView.
The challenge lies in disabling the button responsible for triggering the report request after it has been clicked, and then re-enabling it once the report generation is completed to prevent double clicking.
My initial attempt at using prototype.org's Ajax.Request successfully handles the buttons but fails to deliver the PDF to the client. It seems that further steps need to be taken with the response, but I'm unsure of what to do next. Any suggestions or assistance would be greatly appreciated.
function displayPdf(button_b, pdf_url) {
button_b.disabled = true;
new Ajax.Request(pdf_url, {
asynchronous:true,
evalScripts:true,
method:'get',
onComplete: function(response) {
button_b.disabled = false;
},
onFailure: function() {
redAlert('crap');
}
});
}