Ajax Response Content

编程入门 行业动态 更新时间:2024-10-11 21:22:57
本文介绍了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

本文发布于:2023-10-10 09:24:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478290.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Ajax   Response   Content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!