问题
I have created a sample SAPUI5 application in online editor
Check this link to view my code
I am getting this below error -
> XMLHttpRequest cannot load
> http://services.odata.org/V2/Northwind/Northwind.svc/Products?$format=json.
> No 'Access-Control-Allow-Origin' header is present on the requested
> resource.
Can someone help me in solving this issue - I understand that it is CORS issue which can be solved by disabling the security in chrome.
However - I don't to disable the security feature of chrome. So, is there any other way (probably by passing some headers) to solve this issue.
Appreciate your help in advance.
P.S.: I have already looked in these links -
http://scn.sap.com/community/developer-center/front-end/blog/2013/06/29/solving-same-origin-policy-issue-in-different-ways
http://scn.sap.com/community/gateway/blog/2014/09/23/solve-cors-with-gateway-and-chrome
回答1:
If this is just for the purpose of testing, the following solution should be the easiest.
Use a proxy service which adds the needed headers, for example the following: https://github.com/Rob--W/cors-anywhere
Usage is really simple, just add the URL of the proxy service before your OData URL:
var uri = "https://cors-anywhere.herokuapp.com/https://services.odata.org/V2/Northwind/Northwind.svc/Products?$format=json";
回答2:
add the northwind odata service as a destination under the DESTINATIONS tab of your hcp account. Then make an ajax call to the northwind services using relative path i.e. /destination/..... Or make your own java application that works as proxy which allows source as and re-routes the payload to the correct destination.
basically destination is also a proxy supplied for out of the box usage by sap
来源:https://stackoverflow.com/questions/37465851/access-control-allow-origin-error-when-accessing-northwind-odata-service-from-sa