我有一个用户提交的Jquery / HTML表单。我将表单值传递给url 并根据用户表单提交下载Excel文件。
我使用表单值填充url并下载Excel文件。以下示例:
http://localhost:8080/Service/getReport?report=pers_fees_report&startDate=20161201&endDate=20161231&programId=&balanceDate=&delivery=stream"
我试图使用ajax但在这种情况下看起来可能不需要Ajax。
他们是在下载excel文件或无法下载时发送用户反馈的方法吗?是他们的任何一个例子吗?
获取表单值
$("#submit").on('keypress click', function(e){
e.preventDefault();
reportName = $("#reportName").val();
start = $("#start").val();
end = $("#end").val();
sourceId = $("#sourceId").val();
programId = $("#programId").val();
sourceId2 = $("#sourceId2").val();
programId2 = $("#programId2").val();
balance = $("#balanceDate").val();
if(reportName !== '' ){
reportData ="report="+reportName+"&startDate="+start+"&endDate="+end+"&programId="+programId+"&balanceDate="+balance+"&delivery="+stream;
getExcel(newURL,reportData);
//Reset form
// $("form#reportName")[0].reset();
}
});
函数getExcel
function getExcel(newURL,reportData) {
var Report = "http://localhost:8080/Service/getReport?report=pers_fees_report&startDate=20161201&endDate=20161231&programId=&balanceDate=&delivery=stream"
console.log("reportName " + reportName);
console.log("programId " + programId);
console.log("dbalanceDatet " + balanceDate);
console.log("sourceId " + sourceId);
$.ajax({
url: Report,
type: "post",
//data: {report:reportName,startDate:start,endDate:end,programId:programId},
//data: $('form#reportForm').serialize(),
success: function(data, textStatus, jqXHR) {},
error: function(jqXHR, textStatus, errorThrown) {
console.log('FAILED to get JSON from AJAX call' + jqXHR + textStatus + errorThrown);
}
});
}