on 09-29-2017 2:16 PM
I am try consume an xsodata service like Odata in SAPUI5 in Eclipse, but I get some erros:
Failed to load https://.../carimbo.xsodata/$metadata: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost...' is therefore not allowed access.
2017-09-29 10:09:55.242715 [ODataMetadata] initial loading of metadata failed -
Failed to load https://.../carimbo.xsodata/Lacamento: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:...' is therefore not allowed access.
2017-09-29 10:09:55.256280 The following problem occurred: HTTP request failed0,,
Uncaught (in promise) {xmlDoc: document}
Uncaught (in promise) {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…6.140:4311/HelloWorld/carimbo.xsodata/$metadata'.", request: undefined, response: undefined}
Bellow is my code.
Controller:
sap.ui.define([
'jquery.sap.global',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
], function(jQuery, Controller, JSONModel) {
"use strict";
var ListController = Controller.extend("sap.m.sample.ListCounter.List", {
onInit : function (evt) {
var sServiceUrl = "https://.../carimbo.xsodata";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true, "user", "pass");
var oJsonModel = new sap.ui.model.json.JSONModel();
oModel.read("/Lacamento?", null, null, true, function(oData, response) {
oJsonModel.setData(oData);
});
sap.ui.getCore().setModel(oJsonModel);
this.getView().setModel(oJsonModel);
}
});
return ListController;
});
View
<mvc:View
controllerName="sap.m.sample.ListCounter.List"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<List
headerText="Products"
items="{
path: '/results'
}" >
<StandardListItem
title="{CARIMBO}"
/>
</List>
</mvc:View>
Hi,
Please create a destination with the credentials and call it via a model created in manifest.json file and the path is defined in neoapp.json.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Your problem comes from CORS issue. You try to access to an URL from another demain.
For instance your domain is myapp.mycompany.com and you want that app call an url like this thisAPI.anotherdomain.com
This is forbiden by browser, two solutions :
1. Use a reverse proxy
2. for Development only, use a CORS plugin for Chrome
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oula !!!! 🙂 for Reverse proxy, you will need a Apache proxy server (I assume you will not deploy on SAP Cloud Platefrom because it has already a reverse proxy integrated)
Please have a look at this blog
Regards
User | Count |
---|---|
78 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.