通过 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)