Skip to Content
0
Sep 29, 2017 at 01:16 PM

Consuming xsodata in SAPUI5

550 Views

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>