I have Grafana set up in a Docker container (grafana/grafana
image from Docker repo) with port 3000 forwarded to my localhost. My docker-compose.yml
below:
version: '2.1'
services:
grafana:
image: grafana/grafana
ports:
- 3000:3000
Originally I also have link to Graphite and some volumes and environment configuration (GF_SECURITY_ADMIN_PASSWORD
only) but I suppose it does not matter.
I can get a response from Grafana via simple curl
call:
$ curl http://localhost:3000
<a href="/login">Found</a>.
But when I am trying to get it via AJAX call, it gives me a weird result:
$.ajax({url: 'http://localhost:3000', beforeSend: function(xhr, settings) {alert('before setting header'); xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); alert('after setting header');}});
[many JSON fields]
responseText:""
[many JSON fields]
statusText: "error"
[many JSON fields]
Alerts says that header is set to accept requests from any origin.
The same happens (curl works but ajax not) when I am calling Docker container address directly.
What happens in the background? Why the second request does not work? How can I get response from Grafana via AJAX call?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…