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 文件


- addEventListener 在 IE 11 中不起作用 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 400或500级别的HTTP响应 2022-01-01