[英]JS script is not loading in node.js
GET /contact 200 33ms - 2.26kb
GET /stylesheets/bootstrap.css 304 2ms
GET /stylesheets/header.css 304 1ms
GET /stylesheets/style.css 304 2ms
GET /stylesheets/contact.css 304 1ms
GET /javascripts/script.js 404 1ms
It keeps saying 404 when I try to load my javascript file.当我尝试加载我的 javascript 文件时,它一直说 404。 I have no idea why this is not working!
我不知道为什么这不起作用!
here are the lines that include the script:以下是包含脚本的行:
extends layout
block css
link(rel='stylesheet', href='/stylesheets/contact.css')
script(type="text/javascript", src='/javascripts/script.js')
the css is loading fine. css 加载正常。 here is the beginning of the script file:
这是脚本文件的开头:
$(window).load(function() {
function() {
console.log("inside basil script");
so it is definitely not working.所以它绝对不起作用。
Why could this be happening?为什么会发生这种情况? I know it is very simple but I can't figure it out.
我知道这很简单,但我无法弄清楚。 I just started using node.js
我刚开始使用 node.js
PS here is my app.js file (well part of it) PS 这是我的 app.js 文件(很好的一部分)
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
Do you use the http://www.senchalabs.org/connect/static.html middleware in your application to serve directory with clien side javascripts? 您是否在应用程序中使用http://www.senchalabs.org/connect/static.html中间件来为clien side javascripts提供服务? (i am 90% sure that you use expressJS framework).
(我90%肯定你使用expressJS框架)。
Looking at the http codes you showed, I belive you only added one directory to serve static files and not added javascripts
one. 看看你展示的http代码,我相信你只添加了一个目录来提供静态文件,而不是添加一个
javascripts
。
so you have something like 所以你有类似的东西
app.use(express.static(__dirname + '/stylesheets'));
now you need to add 现在你需要添加
app.use(express.static(__dirname + '/javascripts'));
Instead of代替
app.use(express.static(path.join(__dirname, 'public')));
use用
app.use(express.static('public'));
It's work for me这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.