Ajax响应内容处置附件 [英] Ajax Response Content-Disposition attachment

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

问题描述

我建立一个网站,通过JavaScript与接受张贴的JSON请求一个web服务进行通信。我发布使用XMLHtt prequest这些请求。在某些情况下,服务返回下载响应:

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.

我的问题是:我可以实现与XMLHtt presponse对象以某种方式同样的效果?有一个iframe把戏什么的?不幸的是,在XMLHtt prequest对象没有对象构件就像没有对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响应内容处置附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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