on 2020 Jun 18 7:07 PM
Hi,
I am trying to consume an Odata Service through JS code only (No Cloud Connector)
Controller:
var url = "https://services.odata.org/V2/Northwind/Northwind.svc/";
var oModel = new sap.ui.model.odata.v2.ODataModel({ serviceUrl: url});
oModel.read("Categories",
{
method: "GET",
success:
function (data) {
// read data Success },
error:
function () {}
});
I am getting CORS Error as attached in image
Request clarification before answering.
Hi,
You can't use a direct url to another domain in your frontend applications. You'll have to use a proxy for that purpose.
In SAP Cloud Platform you can easily do that by creating a destination and use the destination in your SAPUI5 app.
Creating a destination for the Northwind service is described here:
https://developers.sap.com/tutorials/hcp-create-destination.html
Best regards,
Geert-Jan Klaps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This limitation you're running into is actually a security mechanism of web browsers. Some more information about those can be found here:
https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
https://en.wikipedia.org/wiki/Same-origin_policy
You can't integrate an API call to another domain directly in a frontend application, you'll have to put at least a proxy script which runs within the same domain in between. This can be done using e.g. NodeJS, PHP, ... (or if it's runing in SAP Cloud Platform, by configuring a destination).
Best regards,
Geert-Jan Klaps
User | Count |
---|---|
80 | |
30 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.