如何使用来自服务的响应下载 pdf

How to Download a pdf Using the response from service

本文关键字:响应 下载 pdf 服务 何使用      更新时间:2023-09-26

my code

var url = getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid;
            console.log(url);
            $http.get( url, {cache: false} )
            .success( function( data )
            {
                //success(data);
                console.log(data);
                if(success){
                    window.open( getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid);
                }
            })

我可以下载为pdf,但它在另一个窗口中打开并下载,因为我给了窗口.open。我怎样才能在同一个窗口中制作.就像普通下载一样。我正在使用角度 MVC .

狐狸它工作正常.但是在Chrome中,它正在新窗口中打开

您可以使用 iframe 或 window.location 来代替 window.open(...):

// iframe
var ifrm = document.getElementById(frame);
ifrm.src = getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid;
// in the same window
window.location=getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid;

只需将'_self'作为第二个参数添加到window.open() .

window.open(getApplicationRoot() + '/api/dossier/report/pdfReport?reportId=' + reportid, '_self');

我使用Filament Group的这个jQuery插件做了类似的事情:https://github.com/filamentgroup/jQuery-File-Download