在我的文件中,我有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文件。
要求
但是在这种情况下3,我希望两个文件应同时下载,而不仅仅是一个。
答案 0 :(得分:1)
尝试在
中代替触发成功回调中的click事件window.open(document.getElementById("exportExcelFatturaIcon").href);
window.open(document.getElementById("exportCsvFatturaIcon").href);