问题描述
我有
$.ajax({
url: 'service url',
type: 'POST',
async : true,
contentType: false,
processData: false,
cache: false,
success: function(data){
},
error: function(err){}
});
我可以在chrome检查器的Content-disposition
中看到该文件,并且响应在检查器中显示一个加密的值.
I can see the file in my Content-disposition
in the chrome inspector and the response shows an encrypted value in the inspector.
但是,没有文件正在下载.这里缺少什么?
However, no file is being downloaded. What is missing here?
推荐答案
Content-Disposition
将影响在浏览器窗口中加载资源时发生的情况.
Content-Disposition
will influence what happens when you load a resource in a browser window.
当您使用JavaScript手动处理响应时,它什么也没做.
It doesn't do anything when you are handling the response manually with JavaScript.
如果要从那时开始触发下载,则需要处理响应,生成data:
方案URI并将其设置为location
.
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.
首先将表单提交到目标URL会更简单(除非您不需要POST,在这种情况下,您只需为其设置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).
这篇关于无法使用Ajax jQuery下载Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!