gpt4 book ai didi

javascript - 使用response.sendfile()找不到错误404文件?

转载 作者:太空宇宙 更新时间:2023-11-04 02:01:46 26 4
gpt4 key购买 nike

我的/blog 和/post 在浏览器控制台中触发了许多 404 未找到错误,可以在 here 中找到这些错误即使 blog.html 和 post.html 如果我从文件资源管理器打开它都可以工作! (我的脚本和CSS工作)

我位于/blog 和/post 的 api 端点给了我这些错误,因此 blog.html 或 post.html 的脚本都没有运行。请注意,我的其余 api 工作得很好。

帖子.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>

博客.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>

Node :

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'));
});

最佳答案

看起来目录不正确。因此,它无法加载资源。您可以尝试将它们放在同一个文件夹中或尝试使用像这样的相对路径:

<img src="picture.jpg"> : picture.jpg is located in the same folder as the current page 

<img src="images/picture.jpg"> : picture.jpg is located in the images folder located in the current folder

<img src="/images/picture.jpg"> : picture.jpg is located in the images folder located at the root of the current web

<img src="../picture.jpg"> : picture.jpg is located in the folder one level up from the current folder

关于javascript - 使用response.sendfile()找不到错误404文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45719434/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com