0

I am trying to get the logged Sap Gateway user. The code below is in my controller:

onInit: function (evt) {
  var oUserData;
  var y = "/sap/bc/ui2/start_up";
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      oUserData = JSON.parse(xmlHttp.responseText);
      alert(oUserData);
    } else {
      alert("fail");
    }
  };
  xmlHttp.open("GET", y, false);
  xmlHttp.send(null);
},

When I run my application in Eclipse, it also shows the alert "fail". Why is this happening? Am I doing it wrong?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Rubens Cesar
  • 29
  • 2
  • 3
  • 10

2 Answers2

0

Since you are using Eclipse I believe your application is running on localhost. This means that any relative URL's you use, will be relative to localhost. So /sap/bc/ui2/start_up will be converted to localhost:1234/sap/bc/ui2/start_up.

You will have to use the absolute path to your resource for this to work.

var y = "http://<your_gateway_system>:<port>/sap/bc/ui2/start_up";
Stephen S
  • 3,936
  • 2
  • 23
  • 33
0

Now it's working

Below is my new code

onInit : function (evt) {
        var oUserData;
        var y = "http://<your_gateway_system>:<port>/sap/bc/ui2/start_up";
        var xmlHttp = null;
        xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                oUserData = JSON.parse(xmlHttp.responseText);
               alert(oUserData["fullName"]);
            }
        };
        xmlHttp.open("GET", y, false);
        xmlHttp.send(null);
            },
Rubens Cesar
  • 29
  • 2
  • 3
  • 10