【发布时间】:2016-03-06 17:16:56
【问题描述】:
是否可以将Grafana Http API 与客户端javascript 一起使用? 我从获取已创建仪表板的 json 的最基本知识开始。
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 │
└──────────┘ └───────────┘ └───────────┘
【问题讨论】:
标签: api http cross-domain grafana