【问题标题】:404 error loading a .js file from html script从 html 脚本加载 .js 文件时出现 404 错误
【发布时间】:2018-11-15 15:24:45
【问题描述】:

我是使用 javascript 和 html 的新手。

我一直在学习一个涉及从 Paperjs 代码库加载文件的教程。我正在尝试加载一个 js 文件,其中包含用于在网页上放置图像的函数和对象。

每当我尝试加载“paper-full.js”文件时,我都会在控制台中收到 404 错误,尽管“paper-full.js”文件与“index.html”文件位于同一位置这就需要它了。预览页面也有 localhost IP 地址作为页面的标题,而不是文件名。

这部分教程的目标只是在预览页面的 [0,0] 处放置一张图片。

任何关于错误可能在哪里的想法将不胜感激。

folder containing the paper-full and index files

preview page error for index.html

这里是 index.html 文件

  <!DOCTYPE html>
<html>
    <head>
        <!-- Imports the Paper.js library -->
        <script type="text/javascript" src="js/paper-full.js">
        </script>

        <!-- Connects Paper.js with the HTML canvas -->
        <script type="text/paperscript" src="js/rocket.js" canvas="canvas"></script>        
    </head>
    <body>
        <canvas id="canvas" width="800" height="800"></canvas>
    </body>
</html>

【问题讨论】:

标签: javascript html http-status-code-404 paperjs adobe-brackets


【解决方案1】:

查看您的项目结构,您在index.html 文件旁边有您的paper-full.jsrocket.js 文件,但您在不存在的/js/ 文件夹中查找它们。

试试这个,注意我如何将js/etc 更改为./etc,这意味着它将寻找它的相邻文件。

<!DOCTYPE html>
<html>
    <head>
        <!-- Imports the Paper.js library -->
        <script type="text/javascript" src="./paper-full.js">
        </script>

        <!-- Connects Paper.js with the HTML canvas -->
        <script type="text/paperscript" src="./rocket.js" canvas="canvas"></script>        
    </head>
    <body>
        <canvas id="canvas" width="800" height="800"></canvas>
    </body>
</html>

【讨论】:

  • 谢谢,很高兴这是一个简单的错误,现在我对如何在 js 中导航到文件有了更好的了解
  • @Artistcode 如果您有解决方案,请接受答案!
猜你喜欢
  • 2022-11-14
  • 2015-05-17
  • 2021-12-31
  • 1970-01-01
  • 2020-06-21
  • 1970-01-01
  • 2020-07-20
  • 2012-12-31
相关资源
最近更新 更多