简体   繁体   English

找不到JavaScript文件node.js

[英]Cannot find javascript file node.js

I linked my javascript file in one of my HTML pages but I keep getting the error http://localhost:3000/users/javascript/users-edit.js . 我在一个HTML页面中链接了javascript文件,但http://localhost:3000/users/javascript/users-edit.js收到错误http://localhost:3000/users/javascript/users-edit.js

Here is my application structure: 这是我的应用程序结构:

app/public/javascript/users-edit.js

app/views/users-edit.handlebars

In my app.js file I have: 在我的app.js文件中,我有:

app.use(express.static(__dirname + '/public'));

In my users-edit.handlebars file, I clearly link in my .js file: 在我的users-edit.handlebars文件中,我清楚地链接了.js文件:

<script type="text/javascript" src="javascript/users-edit.js"></script>

Note - I have several other handlebars files where I link the .js file in the exact same manner, but they all work. 注意-我还有其他几个车把文件,它们以完全相同的方式链接.js文件,但它们都起作用。

Can someone help? 有人可以帮忙吗?

You're asking for /users/javascript/users-edit.js but the file is in /javascript/users-edit.js 您要的是/users/javascript/users-edit.js但文件位于/javascript/users-edit.js

Presumably when you said src="javascript/users-edit.js" you forgot to take into account the URL of the page including that HTML might not be in the root of the site, and you should have said src="/javascript/users-edit.js" (explicitly starting the URL resolution from the root instead of the current directory). 大概当您说src="javascript/users-edit.js"您忘记考虑页面的URL,包括HTML可能不在网站的根目录中,因此您应该说src="/javascript/users-edit.js" (明确地从根目录而不是当前目录开始URL解析)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM