1 回答
TA贡献1770条经验 获得超3个赞
正如你所说,你不能同时返回两个响应,我将通过一个文本区域来解决它,其中包含显示失败订单的 CSV 数据,并可以选择将文本下载到文件中
您可以使用此 Javascript 函数从 TextArea 下载文件
function generateTextFile(textareaElement, filenameWithoutExtension) {
var textToWrite = textareaElement.val();
var textFileAsBlob = new Blob([textToWrite], {type:'text/csv'});
var fileNameToSaveAs = filenameWithoutExtension + ".csv";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null) {
// Chrome allows the link to be clicked
// without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
}
else {
// Firefox requires the link to be added to the DOM
// before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
添加回答
举报