Skip to Content

If you are working with SAPUI5/OpenUI5, sooner or later you will come across “No ‘Access-Control-Allow-Origin’ header is present on the requested resource.” This article explains when you get this error and how to resolve it the easiest way particularly for Chrome Browser.

Applies to: Tested for a simple SAPUI5/OpenUI5 desktop App but applies to 7.31, 7.4 versions etc.

Prerequisites

No stringent pre-requisites. This article may be helpful or beginners to experts alike.


Outcome
You will be able to get rid of No “‘Access-Control-Allow-Origin’ header is present on the requested resource.” in Chrome browser


Problem

An application with seemingly correct code does not run properly in the chrome browser. Inspection in F12 developer tools reflects the following error –
Access-Control-Allow-Origin’ header is present on the requested resource.

ActualOutput.jpg

While the expected output is –
AppWorks.jpg

In Internet Explorer it warns you but lets you run the application if you accept the risk and chose to allow blocked content-

IEPopUp.jpg

When you chose to run the app allowing blocked content it runs –IEPopUpWorks.jpg

Resolution

This error message in Chrome Browser means that some parts of your application do not have the same origin which looks suspicious and to alert and block, malicious (cross-site) attempt to access productive applications or steal some data from them. You might face this error when your application code is perfectly alright. I got this error in Chrome while trying to run a very simple application. At the same time Internet Explorer ran the application without a problem.


We need to tell the browser programmatically in http headers that content from different servers is not a problem and we are doing it on purpose.


There are different ways to achieve the same.


Resolution Option 1

Start the Chrome browser from command prompt with a flag to ignore cross-site content

E.g ‘path to your chrome installation\chrome.exe –allow-file-access-from-files’

Surprisingly for my current application this option did not help.

Resolution Option 2

Add the Chrome addon from the following link –

Allow-Control-Allow-Origin: * – Chrome Web Store

Once added to Chrome, just toggle the switch where the switch turns blue and the button above turns green.

After this step, just run your application as you were trying to do earlier and it should run just fine.

/wp-content/uploads/2015/02/addon_649631.jpg


Resolution Confirmation

Enjoy your application working !

AppWorks.jpg


Code for simulating the above scenario

(just copy paste the given code in a text file with .html extension and run it with IE or Chrome)

<!DOCTYPE HTML>

<html>

  <meta http-equiv=”X-UA-Compatible” content=”IE-edge”>

  <meta charset=”UTF-8″>

  <head>

  <title>MY SAPUI5 APP</title>

  <script src=”https://sapui5.hana.ondemand.com/resources/sap-ui-core.js

  id=”sap-ui-bootstrap”

  data-sap-ui-libs=”sap.ui.commons, sap.ui.table, sap.ui.ux3″

  data-sap-ui-theme=”sap_corbu”>

  </script>

  <script>

  var oShell = sap.ui.ux3.Shell({

  appTitle: “MY SAPUI5 APP”,

  showLogoutButton:true,

  showSearchTool:true,

  showFeederTool:true

  });

  oShell.placeAt(“app”);

  </script>

  </head>

  <body id=”app” class=”sapUiBody” role=”application”>

  </body>

</html>

A note for the readers
Please do rate the document and let me know views on the content of the document and terminology used. I will be happy to revise the document to accomodate your suggestions.







To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

    1. Amol Gupta Post author

      Hi Akshay,

      I do understand that you have a problem and its not solved but you have not given me anything to look into your problem. Some more description, screenshots etc really help people help you.

      The article above simulates the problem when loading the libarary files:

      <script src=”https://sapui5.hana.ondemand.com/resources/sap-ui-core.js“…

      My guess is that your problem might be caused during calling the OData service, which is usually solved by using “proxy/http/….” in place of “http://….” as OData service URL.

      For example :

      “proxy/http/services.odata.org/Northwind/Northwind.svc”

      in place of

      http://services.odata.org/Northwind/Northwind.svc

      If this is not the case, please share your Chrome console output here, also raise a question in Forums with a elaborate problem description and screenshots to involve the whole UI5 community.

      Regards,

      AG.

      (0) 

Leave a Reply