0

I am trying to load data from grafana using Javascript XMLHTTPRequest. Following is my code,

function populateIframe(  ) {
          var xhr = new XMLHttpRequest();

          xhr.open('GET', 'http://username:password@localhost:3000/api/org');
          xhr.onreadystatechange = handler;
          xhr.send();

          function handler() {
              debugger;
            if (this.readyState === this.DONE) {
              if (this.status === 200) {
                // this.response is a Blob, because we set responseType above
                document.getElementById("iframe").src = URL.createObjectURL(this.response);
              } else {
                console.error('XHR failed', this);
              }
            }
          }

I am getting status code as 0. And i also tried Ajax call to get Grafana response, But still am not getting any proper data. Can someone guide me to solve this.

Thanks in advance.

kumaranc
  • 105
  • 1
  • 11
  • How is the website that includes that script served? From `http://localhost`? Or `http://localhost:3000`? If the former, are you setting CORS headers? –  Dec 31 '18 at 09:54
  • For basic authentication I am mentioned like above. My goal is to access multiple organizations in grafana by an authenticated manner. – kumaranc Jan 01 '19 at 06:20
  • I asked you two fairly simple questions. If you can't answer them, I can't help you. –  Jan 02 '19 at 13:00
  • Hi Chris, I am using http://localhost:3000. Am not added CORS header. Even my code changes are not reflected in application. – kumaranc Nov 21 '19 at 17:54

0 Answers0