[英]SAPUI5 POST Requests always result in 500 Server Error (OData)
我目前正在嘗試學習 SAPUI5 和 OData 的基礎知識。 我正在構建一個簡單的應用程序,其中員工數據顯示在表格中,您可以添加一個新員工,其數據將寫入 SAP 后端。
所有 GET 請求都有效,但是 POST 請求總是導致服務器錯誤 (500)。 我的創建方法是否格式不正確或者我忘記了什么(特殊的 header 等)? (我知道我實際上應該使用 odata.v2 但只是為了這個例子......有什么明顯的錯誤我只是沒有看到嗎?)
sap.ui.controller("zemployee_crud.EmpTable", {
onInit: function() {
var oView = this.getView();
var oTable = this.byId("employeeTable");
var oTemplate = new sap.m.ColumnListItem({
cells: [new sap.m.Text({
text: "{Empid}"
}), new sap.m.Text({
text: "{Empname}"
}), new sap.m.Text({
text: "{Empadd}"
})]
});
var sServiceUrl = "proxy/http/<server>:<port>/sap/opu/odata/sap/ZEMPLOYEE_SRV";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, false);
this.getView().setModel(oModel);
oTable.bindAggregation("items", {
path: "/EmployeeSet",
template: oTemplate
});
},
Save: function() {
var oId = this.getView().byId("Id").getValue();
var oName = this.getView().byId("Name").getValue();
var oAddress = this.getView().byId("Address").getValue();
var oDialog = this.getView().byId("Dialog");
var oEntry = {};
oEntry.Empid = oId;
oEntry.Empname = oName;
oEntry.Empadd = oAddress;
var oModel = this.getView().getModel();
oModel.create("/EmployeeSet", oEntry, null, function (response) {
alert("Success!");
// handle response
}, function (Error) {
alert("Fail!");
// handle response
});
}
這是 UI5 開發中的常見場景。 SAP 網關服務器不會告訴前端確切的錯誤,因為這可能會泄漏您不希望的數據。
要找出確切的問題是什么,您應該 go 到您后端的事務 /IWFND/ERROR_LOG。 那里的請求應該是可見的,你可以看到究竟是什么導致了這個錯誤。
終於找到錯誤了——通過Eclipse創建的BSP應用程序有問題。 修復此問題后,POST 請求運行良好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.