无法从 Eclipse 连接到 SAP Gateway
Failed to connect to SAP Gateway from Eclipse
我正在尝试获取已登录的 Sap Gateway 用户。下面的代码在我的控制器中:
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);
},
当我 运行 我的应用程序在 Eclipse 中时,它也显示警告“失败”。为什么会这样?我做错了吗?
由于您使用的是 Eclipse,我相信您的应用程序在本地主机上 运行。这意味着您使用的任何 URL 相对于本地主机。所以/sap/bc/ui2/start_up会被转换为localhost:1234/sap/bc/ui2/start_up。
您必须使用您的资源的绝对路径才能正常工作。
var y = "http://<your_gateway_system>:<port>/sap/bc/ui2/start_up";
现在可以使用了
下面是我的新代码
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);
},
我正在尝试获取已登录的 Sap Gateway 用户。下面的代码在我的控制器中:
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);
},
当我 运行 我的应用程序在 Eclipse 中时,它也显示警告“失败”。为什么会这样?我做错了吗?
由于您使用的是 Eclipse,我相信您的应用程序在本地主机上 运行。这意味着您使用的任何 URL 相对于本地主机。所以/sap/bc/ui2/start_up会被转换为localhost:1234/sap/bc/ui2/start_up。
您必须使用您的资源的绝对路径才能正常工作。
var y = "http://<your_gateway_system>:<port>/sap/bc/ui2/start_up";
现在可以使用了
下面是我的新代码
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);
},