Ajax Response Content-Disposition 附件 [英] Ajax Response Content-Disposition attachment

查看:47
本文介绍了Ajax Response Content-Disposition 附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个网站,该网站通过 javascript 与接受已发布的 json 请求的网络服务进行通信.我使用 XMLHttpRequest 发布这些请求.在某些情况下,服务会返回下载响应:

I am building a website that communicates via javascript with a webservice that accepts posted json requests. I Post these requests using XMLHttpRequest. In some cases the service returns a download response:

示例:

Content-Disposition: attachment; filename="somefile.txt"
Content-Type: application/force-download
Content-Length: 3

123

如果 document.location 指向的 URL 提供类似上面的响应,浏览器将自动提示用户一个文件下载对话框.

if document.location is pointed to an URL that serves a response like the one above, the browser will automatically prompt the user with a file download dialog.

我的问题是:我可以用 XMLHttpResponse 对象以某种方式达到相同的效果吗?有没有 iframe 技巧之类的?不幸的是,XMLHttpRequest 对象上没有像 html 表单那样的目标成员,因为如果我可以将完整响应(带标题)重定向到新页面或隐藏的 iframe,我猜问题就会解决.

My question is: Can I achieve the same effect with XMLHttpResponse objects somehow? is there an Iframe trick or something? Unfortunately there is no target member on XMLHttpRequest objects like there is on html forms, cause if I could just redirect the full response (with headers) to a new page or hidden iframe the problem would be solved, I guess.

推荐答案

我想不是.但是您可以尝试将隐藏的表单提交到隐藏的 iframe.

I guess not. But you can try submitting hidden form to a hidden iframe.

这篇关于Ajax Response Content-Disposition 附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆