[英]unable to download excel file using ajax jquery
I have 我有
$.ajax({
url: 'service url',
type: 'POST',
async : true,
contentType: false,
processData: false,
cache: false,
success: function(data){
},
error: function(err){}
});
I can see the file in my Content-disposition
in the chrome inspector and the response shows an encrypted value in the inspector. 我可以在chrome检查器的“
Content-disposition
中看到该文件,并且响应在检查器中显示一个加密的值。
However, no file is being downloaded. 但是,没有文件正在下载。 What is missing here?
这里缺少什么?
Content-Disposition
will influence what happens when you load a resource in a browser window. Content-Disposition
将影响在浏览器窗口中加载资源时发生的情况。
It doesn't do anything when you are handling the response manually with JavaScript. 当您使用JavaScript手动处理响应时,它不会执行任何操作。
If you want to trigger a download from that point, you'd need to handle the response, generate a data:
scheme URI and set location
to it. 如果要从那时开始下载,则需要处理响应,生成一个
data:
scheme URI并为其设置location
。
It would be simpler to submit a form to the destination URL in the first place (unless you don't need POST in which case you can just set location
to it). 首先将表单提交到目标URL会更简单(除非您不需要POST,在这种情况下,您只需为其设置
location
即可)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.