且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SAPUI5/AJAX,提交基本认证细节

更新时间:2023-12-04 09:12:22

以下问题可能是问题所在:

The following issues might be the problem:

1) 发送前用户名类型是否为:USERNAME@COMPANY:PASSWORD?

1) Is Username of Type: USERNAME@COMPANY:PASSWORD before sent?

2) 端点 URL 应该根据您的数据中心,也许 DC2 是正确的,但也可能是 DC12 ?https://api12.successfactors.eu/odata/v2/PerPerson?$select=personId 而不是 https://api2.successfactors.eu/odata/v2/PerPerson?$select=personId

2) Endpoint URL should be according to your data center, maybe DC2 is correct, but could also be DC12 ? https://api12.successfactors.eu/odata/v2/PerPerson?$select=personId instead of https://api2.successfactors.eu/odata/v2/PerPerson?$select=personId

3) 传递对成功函数的引用

3) Pass a reference to your success function

var that = this;

....
success: function (data, textStatus, jqXHR) {
     var oModel = that.getView().getModel(); // get your model, instatiated outside this method
     oModel.setData({
        modelData: data
     });
     alert("success to post");
},
     error: function (oError) {
        console.log(oError);
}
....

4) 使用 SAP Cloud Platform 避免跨域问题的正确方法!

4) Working with SAP Cloud Platform the right way to avoid cross-origin problems!

目标(连接 -> 目标):

Destination (Connectivity -> Destinations) in SAP CP:

不要忘记检查连接并接收 HTTP 状态代码 = 200!

Don't forget to check the connection and receive HTTP status code = 200!

Name: sap_hcmcloud_core_odata, 
Type: HTTP
URL:  https://api12preview.sapsf.eu
Auth: Internet, Basic Authentication
  Your User (Username@Company), 
  Your Password
Properties  
  WebIDEEnabled = true
  WebIDESystem = SFSF
  WebIDEUsage = odata_gen

neo-app.json 添加路由:

{ "path": "/sf-dest",
    "target": {
        "type": "destination",
        "name": "sap_hcmcloud_core_odata"
    },
    "description": "SFSF Connection"
}

在您的控制器

sap.ui.define([
"sap/ui/core/mvc/Controller"], function (Controller) {
"use strict";

return Controller.extend("yourNamespace.yourAppName.controller.Main", {
    onInit: function () {
        var oModel = new sap.ui.model.json.JSONModel();
        var sHeaders = {
            "Content-Type": "application/json",
            "Accept": "application/json",
        };

        //sending request
        oModel.loadData("/sf-dest/odata/v2/PerPerson?$select=personId", null, true, "GET", null, false, sHeaders);
        console.log(oModel);

    }
});
});