1
我有一个碧玉报告,我需要使用AJAX但是要打印,与jQuery的AJAX调用它不工作:如何使用AJAX下载Jasper报告的PDF档案?
$.ajax(
{
method: 'POST',
url: 'ExportReport',
async : false,
data: {
typeOfClient : _type,
mouthOfSelect : _mounth
},
success : function (html) {
alert("Sucess");
}
如果我使用提交表单,这项工作:
//create dynamic form
var formularioElement = document.createElement('form');
formularioElement.setAttribute('id', 'formSync');
formularioElement.method = 'POST';
formularioElement.action = 'ExportReport';
// Create input
var formularioInput = document.createElement('input');
formularioInput.type = 'text';
formularioInput.name = 'typeOfClient';
formularioInput.value = _type;
// Create input 2
var formularioInput2 = document.createElement('input');
formularioInput2.type = 'text';
formularioInput2.name = 'mouthOfSelect';
formularioInput2.value = _mouth;
formularioElement.appendChild(formularioInput);
formularioElement.appendChild(formularioInput2);
// add the form to DOM
document.body.appendChild(formularioElement);
// submit
formularioElement.submit();
这两个代码调用服务器端并创建PDF等于jasper,但只是form.submit()
做下载文件,the ajax code
不下载文件。
我可以用AJAX做到吗?
从技术上讲,这个问题与使用AJAX下载PDF无异。 JasperReports与问题无关,除非您的代码在使用JasperReports生成报告时遇到问题。 –
是的,你是可靠的,我只需要下载一个带有AJAX的pdf文件,你知道这是否可能? – sergioBertolazzo
考虑使用Servlet而不是AJAX。 HTML不需要比'Download'复杂。适用于所有浏览器,不需要AJAX。如果要隐藏参数,请使用提交按钮将其设置为HTML表单,该按钮会向Servlet发出HTTP POST请求,而不是GET请求。 –