2017-08-16 4 views
1

ファイルエクスプローラから開くと、blog.htmlとpost.htmlの両方が動作するにもかかわらず、ブラウザのコンソールでMy/blogと/ postが多くの404エラーを検出しました。hereが見つかりました! (私のスクリプトとCSSの仕事)エラー404ファイルがresponse.sendfile()を使用して見つかりませんでしたか?

私のapiエンドポイントは/ blogと/ postで私にこれらのエラーが出るので、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')); 
}); 

答えて

0

ディレクトリが正しくないように見えます。したがって、リソースをロードできませんでした。あなたは、同じフォルダにそれらを置くか、またはこのようないくつかの相対パスを使用しようとしようとすることができます :

<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 
+0

私はそれがここに私の構造に応じて右のようだと思う:http://imgur.com/a/MNX5Eそれは私のpost.htmlファイルを使って作業しています。また、自分の投稿に編集を追加しました。コンソールのファイルにカーソルを合わせると、localhost:3000/css/style.cssのようなものが得られます。それが正しいかどうかわからない – user8448149

+0

相対パスを使用する必要があるかもしれません:../picture.jpg。 localhost:3000などのURLの前に何があっても、現在のフォルダのディレクトリベースを取得します – NNguyen

+0

現在のフォルダでは、私のノードserver.jsファイルですか?私はそのような場合public/css/style.cssのようなものを試しましたが、まだそれを見つけることはできません。私もそれらをhtmlファイルに関連させて作ってみましたが、それもうまくいきません。 – user8448149

関連する問題