問題描述
通過 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 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!