通过 XHR 请求下载 PDF 文件

PDF file download through XHR Request(通过 XHR 请求下载 PDF 文件)

本文介绍了通过 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 文件

基础教程推荐