我的 dojo 仅在通过 HTTP 访问时有效

发布于 2024-10-09 16:41:30 字数 175 浏览 0 评论 0原文

我下载了 dojo 工具包并打开 dijit/themes/themeTester.html。道场不能工作。我必须将该工具包复制到我的 Web 服务器的 webapp 目录中。然后我通过 HTTP 访问相同的 html。道场工作了。

在开发过程中,我是否必须始终将页面部署到Web服务器进行测试?

谢谢。

I downloaded the dojo toolkit and open the dijit/themes/themeTester.html. The dojo can't work. I have to copy the toolkit to the webapp directory of my web server. Then I access the same html through HTTP. The dojo works.

During the development, do I have to always deploy a page to web server for testing?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

極樂鬼 2024-10-16 16:41:30

此行为不是 Dojo 特有的。出于安全原因,某些浏览器(例如 Firefox)禁止直接从文件系统加载的网页加载其主目录之外的资源。

示例:您的网页位于 /home/bob/page.html 中。它可以包含以下资源:

  • bob.js (有效路径:/home/bob/bob.js
  • ./sam.js (<代码>/home/bob/sam.js)
  • abc/spot.js (/home/bob/abc/spot.js
  • 等等

) 无法加载以下资源(即使存在):

  • ../bob.js (/home/bob.js)
  • /home/tom/script.js
  • ../tom/script.js (/home/tom/script.js)

理论上你可以进入 Firefox 内部并关闭这个“功能” ,但您可能会遇到其他问题:

  • 在某些情况下,XHR 在文件系统中的工作方式很有趣。 Web 服务器随文件发送 MIME 标头,而文件系统不提供此服务,XHR 被迫猜测。有时它会猜错。
  • 虽然 Dojo 不需要任何服务器端代码,但它的测试可能会使用 PHP 来模拟服务器端数据存储和其他东西。当从文件系统运行时,这些 PHP 文件通常按原样提供,而不是被执行。

除此之外,您应该能够直接从文件系统运行任何 Web 应用程序。只需确保整个应用程序位于一个文件夹中,所有 HTML 页面都位于顶部文件夹中(或子文件夹中,但不要使用它们“上方”的任何内容),避免绝对路径和“向上”符号 (..)位于将您带出主文件夹(即使是暂时的)的路径中,并始终测试您的 XHR 响应。

This behavior is not Dojo-specific. Some browsers (Firefox comes to mind) prohibit web pages loaded directly from file system to load resources outside of their home directory for security reasons.

Example: your web page is in /home/bob/page.html. It can include following resources:

  • bob.js (effective path: /home/bob/bob.js)
  • ./sam.js (/home/bob/sam.js)
  • abc/spot.js (/home/bob/abc/spot.js)
  • and so on

It cannot load following resources (even if they exist):

  • ../bob.js (/home/bob.js)
  • /home/tom/script.js
  • ../tom/script.js (/home/tom/script.js)

Theoretically you can go into Firefox guts and turn this "feature" off, but you may encounter other problems:

  • In some cases XHR works funny from file system. Web servers send MIME headers with files, while file system doesn't provide this service, and XHR is forced to guess. Sometimes it guesses wrong.
  • While Dojo doesn't need any server-side code, its tests may use PHP to emulate server-side data stores and other things. When running from file system, those PHP files are usually served as is, instead of being executed.

Other than that you should be able to run any web application directly from file system. Just make sure that the whole app is inside one folder, all HTML pages are in the top folder (or in subfolders, but do not use anything "above" them), avoid absolute paths, and "go up" symbols (..) in paths that take you outside of the main folder (even temporarily), and always test your XHR responses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文