Javascript文件未在express / node.js中加载

时间:2022-07-25 14:01:49

I have a problem where my javascript file is not loading. Here is my file directory:

我有一个问题,我的javascript文件没有加载。这是我的文件目录:

app/views/methods.js app/views/methods.handlebars

I want to load the methods.js file in the methods.handlebars page:

我想在methods.handlebars页面中加载methods.js文件:

<script type="text/javascript" src="./views/methods.js"></script>
<div class="container">
  <div class="form-group">
    <label>First Number:</label>
    <input type="text" name="firstNum">
  </div>
  <div class="form-group">
    <label>Second Number:</label>
    <input type="text" name="secondNum">
  </div>
  <button type="" name="calculate" class="btn btn-default">Calculate</button>
</div>

However, I keep getting a cannot GET error in the console... can someone help?

但是,我一直在控制台中得到一个无法GET错误...有人可以帮忙吗?

Thanks!

2 个解决方案

#1


2  

I think your problem might be related to it being in the Views directory.

我认为你的问题可能与它在Views目录中有关。

Try creating a directory for scripts in the public directory.

尝试在公共目录中为脚本创建目录。

So assuming you create a javascript directory that would make your call to get the script as

因此,假设您创建了一个javascript目录,可以调用脚本来获取脚本

<script type="text/javascript" src="javascript/methods.js"></script> 

#2


0  

I'm a total noob at this - i forgot that I need to reset the node server whenever i make server-side code changes. What I have totally works.

我这是一个完全的菜鸟 - 我忘了每当我更改服务器端代码时我都需要重置节点服务器。我完全有效。

#1


2  

I think your problem might be related to it being in the Views directory.

我认为你的问题可能与它在Views目录中有关。

Try creating a directory for scripts in the public directory.

尝试在公共目录中为脚本创建目录。

So assuming you create a javascript directory that would make your call to get the script as

因此,假设您创建了一个javascript目录,可以调用脚本来获取脚本

<script type="text/javascript" src="javascript/methods.js"></script> 

#2


0  

I'm a total noob at this - i forgot that I need to reset the node server whenever i make server-side code changes. What I have totally works.

我这是一个完全的菜鸟 - 我忘了每当我更改服务器端代码时我都需要重置节点服务器。我完全有效。