在我的文件中,我有2个锚标签,上面有其HREF。我在 ajax调用成功中击中两个锚标签。
<a id="exportExcelFatturaIcon" href ="${createLink(action: 'downloadExcel', params: [fileName:excelFileName])}" hidden>click here</a>
<a id="exportCsvFatturaIcon" href ="${createLink(action: 'downloadCSV', params: [fileName:csvFileName])}" hidden>click here</a>
ajax调用:
$("#exportFatturaButton").click(function(){
var startDate = $("#startDateFattura").val();
var endDate = $("#endDateFattura").val();
$("#loaderModal").modal('show');
$.ajax({
url: "${createLink(controller: 'ExportData',action: 'getDataBySearch')}",
data: {
startDate: startDate,
endDate:endDate
},
dataType: "html",
type: "POST",
success: function (data) {
$("#loaderModal").modal('hide');
document.getElementById("exportExcelFatturaIcon").click();
document.getElementById("exportCsvFatturaIcon").click();
},
error: function (xhr, status) {
$("#loaderModal").modal('hide');
}, complete: function (xhr, status) {
$("#loaderModal").modal('hide');
}
});
});
问题案例
情况1:当我仅点击document.getElementById("exportExcelFatturaIcon").click();
时,只会下载excel
文件。
情况2:当我仅点击document.getElementById("exportCsvFatturaIcon").click();
时,只会下载csv
文件。
案例3:当我击中两个 document.getElementById("exportExcelFatturaIcon").click();
document.getElementById("exportCsvFatturaIcon").click();
然后只有csv
文件将不是Excel文件。
要求
但是在这种情况下,我希望两个文件不仅要同时下载。
而不是触发成功回调中的单击事件,请尝试
window.open(document.getElementById("exportExcelFatturaIcon").href);
window.open(document.getElementById("exportCsvFatturaIcon").href);