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

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

问题描述

我有angularjs应用程序,用户输入保存到数据库的数据,然后在服务器端编译成pdf文件。所有访问都需要适当的身份验证头。填写所需数据后,用户按下按钮保存数据,然后检索pdf文件。最佳的方法是在我的angularjs应用程序中调用$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $这个工作很好,在另一个窗口中打开,但是如何在这个 $ 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天全站免登陆