I have a controller (Spring-MVC) that generates a PDF report on a get request. The controller sets headers like "application/OCTET-STREAM", "Content-Disposition", "attachment; filename=\"" + filename + "\"" so that the user gets the save/open dialog forced to them. The controller gets a pdf generated and writes the pdf bytes directly to the response's output stream. The ModelAndView that is returned is null.
The issue is I need/want to disable the button that generates the report request after it is clicked and then re-enable it when the report is finished in order to prevent double clicking.
I thought I could use prototype.org's Ajax.Request to do this... This bit of code does work the buttons properly but then I'm stuck because the client never gets the pdf. I'm guessing I need to do something with the response but I don't know what. Any ideas/help is 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');
}
});
}