Skip to Content
0
May 12, 2016 at 05:11 PM

How to load external .js file in Web IDE

484 Views

Hello,

I am trying to load javascript file deployed in HCP (say for example https://xxx.dispatcher.hanatrial.ondemand.com/library/abc.js) in my Web IDE UI5 application. I am able to access the js directly using the above url. I tried with two approaches, but nothing worked.

Approach 1: Mentioned the following in index.html

<script>

jQuery.sap.registerModulePath("custom", "https://xxx.dispatcher.hanatrial.ondemand.com/library/abc.js");

</script>

However, I am getting the following error:

sap-ui-core.js:71 XMLHttpRequest cannot load https://xxx.dispatcher.hanatrial.ondemand.com/library/abc.js. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://callreuse-p364990trial.dispatcher.hanatrial.ondemand.com' is therefore not allowed access. The response had HTTP status code 404.

Approach 2: I have created an destination (named ReuseControl) in HCP cockpit using https://xxx.dispatcher.hanatrial.ondemand.com and referred it neo-app.json.

{

"path": "/ReuseLib",

"target": {

"type": "destination",

"name": "ReuseControl"

},

"description": "Test"

}

When I tried to use it in index.html as:

<script>

jQuery.sap.registerModulePath("custom", "/ReuseLib/library");

</script>

and referred abc.js using the alias "custom", it says that the .js file is not found though I can see the abc.js file Network tab of chrome. If I open abc.js from Network tab, it says: HTTP Status 405 - Bad Method. If I refresh the page again, I can see abc.js content in browser.

My question is: What should be the ideal approach to load external .js file in UI5 application developed using WEB IDE? Can you please suggest a way to make the above scenario working?

Regards,

Faddy