如何认证头添加到$ window.open [英] how to add authentication header to $window.open

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

问题描述

我有,用户输入保存到数据库中的数据angularjs应用程序,然后在服务器端被编译成pdf文件。所有访问都需要建立适当的认证头。需要经过数据填充用户presses按钮保存数据,然后检索PDF文件。理想情况下,我在angularjs应用程序调用$ window.open(url_generating_pdf)。这种运作良好,并在另一个窗口打开,但如何认证头添加到该窗口$要求?在我的理解,我不能下载PDF文档,并与阿贾克斯打印出来,所以我缺少这个认证。或者会有其他的方式来调用来自服务器的URL,并在另一个窗口中打开该文件?

I have angularjs application where users enter data that is saved to database, and 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天全站免登陆