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?
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";