PDF file download through XHR Request(通过 XHR 请求下载 PDF 文件)
问题描述
通过 XHR 请求下载 pdf 文件是完全不可能的吗?我知道已经有很多关于这个话题的其他讨论,但遗憾的是,我仍然对它们不满意.我正在使用 AngularJs 并使用其 $Http
方法发出请求.它不返回任何文件下载弹出窗口.但是,如果我在新的浏览器窗口中使用相同的 URL,那么我会得到一个弹出窗口.我已经尝试过一个工作区,它的工作正常,即 document.location.href = url;
但如果我这样做,那么在下载弹出窗口准备好之前,我无法显示等待图像并出现了.所以周围的工作对我来说是不够的.我想以一种真正的方式通过向服务器发出请求来完成它,通过它我也可以处理结果的替代流程.
Is it totally impossible to download a pdf file through an XHR request?
I know there are many other discussions already on this topic but sadly, I am still not satisfied with them.
I am using AngularJs and making a request by using its $Http
method. It is not returning any file download popup. But if I hit with the same URL in a new Browser Window then I am getting a popup.
I have already tried a work-arround and its working fine i.e. document.location.href = url;
but If I do this then I am unable to show the waiting image till the time the download popup is ready and appeared.
So the work arround is not enough for me. I would like to do it with a genuine way through a request to the server through which I can handle the alternative flows of the outcome as well.
推荐答案
看看这个JQuery插件jquery-file-download-plugin 这里是这个插件的演示页面 demo.我认为它将 iframe 动态插入到 DOM 并产生类似于 AJAX 请求的外观.可能对你有帮助.
Have a look at this JQuery plugin jquery-file-download-plugin and here is the demo page of this plugin demo . I think its inserting iframe dynamically to DOM and produces look and feel just like AJAX request. It might be helpful for you.
这篇关于通过 XHR 请求下载 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 XHR 请求下载 PDF 文件


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01