Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
amolgupta
Active Contributor

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.

While the expected output is -

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

When you chose to run the app allowing blocked content it runs -

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.


Resolution Confirmation

Enjoy your application working !


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.







6 Comments
Labels in this area