Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Grafana Http API与客户端javascript结合使用_Api_Http_Cross Domain_Grafana - Fatal编程技术网

如何将Grafana Http API与客户端javascript结合使用

如何将Grafana Http API与客户端javascript结合使用,api,http,cross-domain,grafana,Api,Http,Cross Domain,Grafana,是否可以与客户端javascript一起使用? 我从获取已经创建的仪表板的json开始 function getHome2Dashboard(callback) { $.ajax({ type: 'GET', url: 'http://localhost:3000/api/dashboards/db/home-2', crossDomain: true, dataType: 'json', headers: { "Au

是否可以与客户端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);
  }
}); 
但我得到一个:

请求的资源上不存在“Access Control Allow Origin”标题

我还尝试使用
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  │
└──────────┘           └───────────┘           └───────────┘
//现在我想到的是:
┌──────────┐           ┌───────────┐
│  浏览器│  │  格拉凡纳│
└──────────┘           └───────────┘
//为了克服跨国问题,
//我应该做这样的事情吗
┌──────────┐           ┌───────────┐           ┌───────────┐
│  浏览器│  │  Web api│  │  格拉凡纳│
└──────────┘           └───────────┘           └───────────┘
据了解,Grafana目前无法直接在服务器中设置CORS头,因此您需要将Grafana服务器置于像nginx这样的反向代理之后,并在那里添加头

请参阅以了解您所面临的问题