cancel
Showing results for 
Search instead for 
Did you mean: 

How to load external .js file in Web IDE

fahad_saplearning
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

jibin_joy
Contributor
0 Kudos

Hi Faddy ,

2nd Approach by creating Destination ...

Regards,

Jibin Joy

fahad_saplearning
Participant
0 Kudos

Alright Jibin.

Can you tell me why the 2nd approach is not wroking for me?

Regards,

Faddy

jibin_joy
Contributor
0 Kudos

Hi Faddy ,

Can I know which type of destination u have used and it will great u have share the screen shot of destination !!! 

Regards,

Jibin Joy

fahad_saplearning
Participant
0 Kudos

Hi Jibin,

Please find the screen shot of the destination which I have created in HCP.

I have used this destination in other HCP project to  load the javascript file. Though the calling app is able to get the correct url using this destination, I can see it returns "HTTP Status 405 - Bad Method" error in Network tab. If I open the file directly in browser once again, it is showing the javascript file content.

Regards,

Faddy

jibin_joy
Contributor
0 Kudos

Hi Faddy ,

   Even we have faced similar issue using basic authentication then we moved Application-to-Application SSO Authentication destination which is working as fine .

  Please ensure this setting for App to App SSO

For More Information : SAP HANA Cloud Platform

Regards,

Jibin Joy

fahad_saplearning
Participant
0 Kudos

Hi Jibin,

You caught it right. Issue resolved. Thanks for your help

Regards,

Faddy

Answers (0)