1
我/博客和/后触发许多找不到404在浏览器的控制台错误,这些错误可以发现here即使blog.html,如果我打开它从我的文件浏览器post.html都工作! (我的脚本和css工作)使用response.sendfile()找不到404错误的文件?
我在/ blog和/ post的api端点给了我这些错误,所以没有运行blog.html或post.html的脚本。请注意,我平静的api的其余部分工作得很好。
Posts.html:
<html>
<head>
<link rel="stylesheet" href = "css/style.css" type="text/css"> </link>
<link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet"> </link>
<script src="js/scripts.js"></script>
<script type="text/javascript" src="jq/jq-datatables-min.js"></script>
<script type="text/javascript" src="jq/jq1-12-4.js"></script>
</head>
<body width="100%" class="body">
<div class = "PostPane">
<form method = "post" action="/postEntry">
Title: <input type="text" name="Title" value="Test"><br>
Month: <input type="text" name="Month" value="August"><br>
Year: <input type="text" name="Year" value="2017"><br>
Paragraph: <input type="text" name="Paragraph" value="Today I added a post method."><br>
<input type="submit" value="Submit">
</form>
</div>
<div class = "DeletePane">
<form method = "post" action="/deleteEntry">
Num: <input type="number" name="Num" value = "9"><br>
<input type="submit" value="Submit">
</form>
</div>
<p>
</p>
</body>
</html>
Blog.html:
<html>
<head>
<link rel="stylesheet" href = "css/style.css" type="text/css"> </link>
<link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet"> </link>
<script type="text/javascript" src="js/scripts.js"></script>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<script>
getEntriesArray();
</script>
<div id="div1">
</div>
</body>
</html>
节点:
app.get('/post', function(req, res) {
res.sendFile(path.join(__dirname, 'public/post.html'));
});
app.get('/blog', function(req, res) {
res.sendFile(path.join(__dirname, 'public/blog.html'));
});
我觉得这似乎是正确的,根据我的结构在这里:http://imgur.com/a/MNX5E它正在使用我的post.html文件。此外,我在帖子中添加了一条修改。当我将鼠标悬停在控制台中的文件上时,我得到了像localhost:3000/css/style.css这样的东西。不知道如果这是正确的 – user8448149
您可能需要使用相对路径:../picture.jpg。这将让该目录基础上当前文件夹无论什么网址之前例如localhost:3000或任何其他 – NNguyen
到当前文件夹,你的意思是我的节点server.js文件?对于这种情况,我尝试了类似public/css/style.css的东西,但仍无法找到它。我也尝试使它们与html文件相关,但这也不起作用。 – user8448149