c# - 使用ajax下载文件在firefox上不起作用
问题描述
我正在尝试使用 Ajax 下载生成的文件(pdf),它在 Chrome 和 IE 中运行良好,但在 FireFox 中却没有。这是我的代码:
function Download(urlAction, urlDownload) {
$.ajax({
type: "post",
url: urlAction,
data: {
'itemIds': checkedItems,
'dateMin': datemin.toISOString(),
'dateMax': datemax.toISOString()
},
datatype: "json",
traditional: true,
success: function (data) {
console.log('fff', data);
if (data.success) {
window.location = urlDownload;
}
}
error: function (xhr, textStatus, err) {
console.log("readyState: " + xhr.readyState);
console.log("responseText: " + xhr.responseText);
console.log("status: " + xhr.status);
console.log("text status: " + textStatus);
console.log("error: " + err);
}
});
}
}
在 UrlAction 中,我生成 Json 格式的文件并将其发布到会话中,然后在我的 urlDownload 中再次调用它。在 Chrome 和 IE 中,文件在不重新加载页面的情况下下载,但在 Firefox 中,它只重新加载页面。
错误说:
- 就绪状态:0
- 响应文本:未定义
- 状态:0
- 文本状态:错误
- 错误:未定义
解决方案
对我有用的是我将按钮(调用此方法的按钮)从表单 div 中取出,它停止重新加载页面,下载就像一个魅力。
推荐阅读
- python-3.x - 使用 Pytorch Lightning DDP 时记录事物的正确方法
- python - 一键执行多项功能 click odoo 11
- java - 如何组织多个HashMap?
- node.js - 是否可以使用 google slide api 复制特定幻灯片?
- reactjs - 保持加载动画启用时如何在 Recharts 中禁用调整大小动画?
- android - 检测我的手机是否连接到我的汽车
- javascript - PWA TypeError:无法获取
- linux-kernel - Energy Aware Scheduler:cpu_capacity 的目的是什么?
- python - 在熊猫中仅保留给定日期列中最后出现的数据
- python - 从音调中去除不需要的频率