0

I'm trying to make a dashboard widget in TFS which retrieves information from my SonarQube 6.1 instance (particularly the code coverage of projects). I'm having trouble accessing the web api. My code to access this data currently looks like this:

                $.ajax
                ({
                    url: myurlapi,
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain: true,
                    username: "",
                    password: "",
                    dataType: 'xml',
                    async: false,

                    success: function (data) {
                        alert(data);
                    },
                    error: function(xhr, status, error) {

                        alert("readyState: " + xhr.readyState);
                        alert("responseText: "+ xhr.responseText);
                        alert("status: " + xhr.status);
                        alert("text status: " + status);
                        alert("error: " + error);
                    }


                })

I'm getting the following error when I try to run this: "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."

I think it's most likely a CORS error as I faced something similar when trying to access Jenkins. I've read that you can't enable CORS from SonarQube, so what alternatives do I have?

Also, the SonarQube server and TFS server are both locally hosted.

slartidan
  • 20,403
  • 15
  • 83
  • 131
kicksticks
  • 239
  • 3
  • 14
  • 1
    As a side note, you should double-check the URL you're requesting. – G. Ann - SonarSource Team May 24 '17 at 18:02
  • @G.Ann-SonarSourceTeam Thanks! Yeah, I have. When I put the URL into my browser I see the information I want. – kicksticks May 24 '17 at 18:08
  • If it was a CORS error, you would be getting a CORS error. i don't see a CORS error in your question, instead i see the kind of error you'd get when requesting something that fails to load (which would indicate a server/network problem) – Kevin B May 24 '17 at 18:21
  • @KevinB Do you have any idea what I could do about that? When I go to the URL manually I can access it fine and the TFS server and Sonarqube server are both working normally. When I google "NetworkError: Failed to execute 'send' on 'XMLHttpRequest':", most threads have people saying it was a CORS error. – kicksticks May 24 '17 at 18:34
  • make sure you have the correct url. protocol and port included. If you aren't getting a CORs error, it isn't a cors error. CORS errors show up in your web console. From what you've presented, either you have the wrong URL, or you can't access it. Neither of which we can help you with. – Kevin B May 24 '17 at 18:41
  • @KevinB I am just getting this error now "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access." – kicksticks May 24 '17 at 20:07
  • 1
    That's much better. That just means the api needs to support CORS. if that isn't possible... you'll have to proxy it somehow. – Kevin B May 24 '17 at 20:33
  • @KevinB Okay I'll look into that - thanks a ton! – kicksticks May 24 '17 at 20:36

0 Answers0