admin管理员组文章数量:1122846
We have a custom library for controlls that we use across different sapui5 apps. For js controls this works fine but now im trying to get it work with a xml fragment.
The library is deployed like an app and contains js files that extends sap/ui/base/Object and works fine. We call it from other apps via
sap.ui.loader.config({
paths: {
'zfiorilibrary': sLibraryPath
}
});
then we can access it from controller of the app by loading it as you load any other objects from sapui5 declaring it at the top in sap.ui.define()
now i tried the same with an xml file that is in the library and it wont load and gives me cors error in console.
this._oAttachmentsMangerDialog = sap.ui.xmlfragment("library-AttachmentsManager", "zfiorilibrary.fragments.AttachmentsManager", this);
jquery-dbg.js:9325 Access to XMLHttpRequest at 'https://ourserver/sap/bc/ui5_ui5/sap/zfiorilibrary/fragments/AttachmentsManager.fragment.xml' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
when i click the url the xml loads fine
we never have cors errors when loading the js files. What can i do to load xml files from the library?
We are using sapui5 version 1.71.x (always the newest 1.71 available)
We have a custom library for controlls that we use across different sapui5 apps. For js controls this works fine but now im trying to get it work with a xml fragment.
The library is deployed like an app and contains js files that extends sap/ui/base/Object and works fine. We call it from other apps via
sap.ui.loader.config({
paths: {
'zfiorilibrary': sLibraryPath
}
});
then we can access it from controller of the app by loading it as you load any other objects from sapui5 declaring it at the top in sap.ui.define()
now i tried the same with an xml file that is in the library and it wont load and gives me cors error in console.
this._oAttachmentsMangerDialog = sap.ui.xmlfragment("library-AttachmentsManager", "zfiorilibrary.fragments.AttachmentsManager", this);
jquery-dbg.js:9325 Access to XMLHttpRequest at 'https://ourserver/sap/bc/ui5_ui5/sap/zfiorilibrary/fragments/AttachmentsManager.fragment.xml' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
when i click the url the xml loads fine
we never have cors errors when loading the js files. What can i do to load xml files from the library?
We are using sapui5 version 1.71.x (always the newest 1.71 available)
Share Improve this question asked Nov 22, 2024 at 4:53 Marvin IngelMarvin Ingel 213 bronze badges 2 |1 Answer
Reset to default 0Javascript files are loaded through <script>
elements which make no-cors
requests. They can be loaded from any origin.
By contrast, XML files cannot be loaded through an HTML element (there is no <xml>
) but only through an XMLHttpRequest
(or an equivalent fetch
). These make cors
requests. If your cross-origin server does not provide the necessary CORS headers, the browser will issue the error message that you observed.
See this documentation about setting CORS headers with your server.
本文标签:
版权声明:本文标题:javascript - How to load sapui5 xml fragment in custom library that gets loaded from another app? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305500a1932613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
library-preload.js
which would allow bypassing a separate request to the XML content. – Boghyon Hoffmann Commented Nov 25, 2024 at 18:07