Loading Dojo Library from AOL and Widget Codes from Local?

[亡魂溺海] 提交于 2019-12-07 14:45:57

问题


I just started to learn Dojo. I followed one site Widget example with some different ways to load Dojo libraries. I like to use AOL reference to load dojo.js like this:

<script type="text/javascript" 
  src="http://o.aolcdn.com/dojo/1.2.0/dojo/dojo.xd.js">
</script>

and saved my widget codes in local web server like this:

scripts/
   myWidget/
     widgetExample.js
   ...
test.html

where widgetExample.js contains my widget class codes, and test.html is my testing page. The error message I got is: "uncaught exception: Could not load cross-domain resources: myWidget.widgetExample ...". I am not sure if I have to load dojo package locally? I really like to separate dojo library package as they are or loaded from AOL and only put my own codes in a local path. I tried to google about different domain loading, baseScriptUrl, and moduleMapping? Still not be able to figure out. Thanks for any detail instructions if any.


回答1:


This may help: http://dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/xdomain-usage-dojo-loading-not-detecting-local-modules

The summary is: you need a djConfig item registering the modulePaths you want to be local, and specify a baseUrl to "trick" Dojo into thinking it knows where those paths are relative, across hosts.

djConfig = { modulePaths: { "mine":"/js/mine" };

then you can dojo.require("mine.Thing") from /js/mine/Thing.js

Regards, Peter Higgins



来源:https://stackoverflow.com/questions/308036/loading-dojo-library-from-aol-and-widget-codes-from-local

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!