我试图在我的angularjs应用程序中嵌入grafana。我可以使用简单的iframe轻松完成,但我的应用程序使用jwt进行身份验证,我无法找到为iframe设置标头的方法。我已经确认,当我使用基本的iframe关闭身份验证时,它的工作完全正常,但我需要在生产中使用它。
我也尝试使用$http
来获取grafana html(这样我可以设置我的jwt标头)但是js似乎不能使用这种方法。我认为它与bootstraping有关,因为它们是手动引导的。
//iframe
<iframe id="grafana" layout-fill flex></iframe>
//controller
$http.get('/grafana/dashboard').then(function(response) {
var iframeDocument = document.getElementById('grafana').contentWindow.document
iframeDocument.open('text/html', 'replace')
iframeDocument.write(response.data)
iframeDocument.close()
})
我可以通过其他方式在iframe上设置标头吗?我也试过使用grafana的html作为模板,但正如我之前说的那样,他们的引导似乎在另一个应用程序中无效。
答案 0 :(得分:0)
你可以通过这种方式进行操作,它应该可以工作:
$.ajax({
type: "GET",
url: "/grafana/dashboard",
contentType: "application/json",
beforeSend: function(xhr, settings){
xhr.setRequestHeader("some_custom_header", "foo");},
success: function(data){
$("#output_iframe_id").attr('src',"data:text/html;charset=utf-8," + escape(data))
}
});