3
是否可以将Grafana Http API与客户端JavaScript一起使用? 我从获取已经创建的仪表板的json的基础开始。如何在客户端使用Grafana Http API javascript
function getHome2Dashboard(callback) {
$.ajax({
type: 'GET',
url: 'http://localhost:3000/api/dashboards/db/home-2',
crossDomain: true,
dataType: 'json',
headers: {
"Authorization": "Bearer eyJrIjoiYkdURk91VkNQSTF3OVdBWmczYUNoYThPOGs0QTJWZVkiLCJuIjoidGVzdDEiLCJpZCI6MX0="
},
success: function(data)
{
if(callback) callback(data);
},
error: function(err)
{
console.log(err);
}
});
但我得到一个:
No 'Access-Control-Allow-Origin' header is present on the requested resource
。
我也尝试过使用jsonp
的方法,开发工具显示服务器发回json数据,但js失败,因为(我认为)结果没有包装在回调函数中。关于如何实现这一欢迎任何建议...
// At the moment I think of something like:
┌──────────┐ ┌───────────┐
│ Browser │ <-------> │ Grafana │
└──────────┘ └───────────┘
// In order to overcome the cross-origin problems,
// should I go towards something like this?:
┌──────────┐ ┌───────────┐ ┌───────────┐
│ Browser │ <-------> │ Web api │ <-------> │ Grafana │
└──────────┘ └───────────┘ └───────────┘