我正在构建一个网站,该网站通过 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
发布评论