如何将身份验证标头添加到 $window.open [英] how to add authentication header to $window.open

查看:134
本文介绍了如何将身份验证标头添加到 $window.open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 angularjs 应用程序,用户可以在其中输入保存到数据库的数据,然后在服务器端将其编译为 pdf 文件.所有访问都需要适当的身份验证标头.填充所需数据后,用户按下按钮保存数据,然后检索 pdf 文件.最理想的是,我在我的 angularjs 应用程序中调用 $window.open(url_generating_pdf) .这很有效并在另一个窗口中打开,但是如何向这个 $window 请求添加身份验证标头?据我了解,我无法下载 pdf,并使用 ajax 打印,所以我错过了此身份验证.或者还有其他方法可以从服务器调用 url,并在另一个窗口中打开文件?

I have angularjs application where users enter data that is saved to database, then on server side it is compiled into pdf file. All access requires appropriate authentication headers in place. After needed data is filled a user presses button to save data and then to retrieve pdf file. Optimally, I call $window.open(url_generating_pdf) in my angularjs app. This works well and opens in another window, but how to add authentication header to this $window request? In my understanding I cannot download pdf, and print it with ajax, so I am missing this authentication. Or would there be other ways to call url from server, and make the file open in another window?

推荐答案

我认为您可以在 URL 中添加此身份验证参数并在您的服务器端执行 GET

I think you can add this authentication parameters in URL and do a GET in your server side

//Add authentication headers as params
var params = {
    access_token: 'An access_token',
    other_header: 'other_header'
};

//Add authentication headers in URL
var url = [url_generating_pdf, $.param(params)].join('?');

//Open window
window.open(url);

这篇关于如何将身份验证标头添加到 $window.open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆