我正在努力教自己前端开发,并遇到了让jquery工作的问题。我在此处发布了我的所有网站:http://mike.shea.sdf.org
在标题和导航按钮之间应该发生什么,应该有博客帖子。这些条目被手工编码到postBuilder.js文件中(与helper.js和jquery lib一起)应生成HTML以显示帖子。
它具有以下结构:
html
index.html
blog.css
js
jquery-2.2.1.min.js
helper.js
postBuilder.js
我对所有内容都有读/权限。
在我自己的机器上本地测试时,一切都很好,但是当发布到服务器时,我在控制台上得到了这个:
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
GET - http://mike.shea.sdf.org/js/jQuery-2.2.1.min.js
如果我将所有内容放在root html文件夹下,它就可以了。我有理由相信我正确输入了相对路径。同样,本地文件具有相同的结构,并且它们可以工作。如果您查看源代码,您会看到我尝试了多个jQuery lib文件并尝试将其放在root html文件夹中。我真的不确定接下来要看什么。这是html文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Contemplating Tech</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles-->
<link href="blog.css" rel="stylesheet">
<script src="/js/jQuery-2.2.1.min.js"></script>
<!-- <script src="./jQuery-2.2.1.min.js"></script> -->
<!-- <script src="https://code.jquery.com/jquery-2.2.1.js></script> -->
<script src="/js/helper.js"></script>
</head>
<body>
<div class="blog-masthead">
<div class="container">
<nav class="blog-nav">
<a class="blog-nav-item active" href="#">Home</a>
<a class="blog-nav-item" href="#">New features</a>
<a class="blog-nav-item" href="#">About</a>
</nav>
</div>
</div>
<div class="container">
<div class="blog-header">
<h1 class="blog-title">Contemplating Tech</h1>
<p class="lead blog-description">Personal musings about technology, web development and whatever else I come across.</p>
</div>
<div class="row">
<div id="posts" class="col-sm-8 blog-main">
<script src="/js/postBuilder.js"></script>
<nav>
<ul class="pager">
<li><a href="#">Previous</a></li>
<li><a href="#">Next</a></li>
</ul>
</nav>
</div><!-- /.blog-main -->
<div class="col-sm-3 col-sm-offset-1 blog-sidebar">
<div class="sidebar-module sidebar-module-inset">
<h4>About</h4>
<p>Mike has been involved with desktop support in one manner or another for 20+ years. This will be both a personal blog and a sandbox as he works on improving his front end web development skill set.</p>
</div>
<div class="sidebar-module">
<h4>Archives</h4>
<p>When I get a little better at getting posts in here and finding how to create an archive, I'll populate a list here.</p>
<!--<ol class="list-unstyled">
<li><a href="#">March 2014</a></li>
<li><a href="#">February 2014</a></li>
<li><a href="#">January 2014</a></li>
<li><a href="#">December 2013</a></li>
<li><a href="#">November 2013</a></li>
<li><a href="#">October 2013</a></li>
<li><a href="#">September 2013</a></li>
<li><a href="#">August 2013</a></li>
<li><a href="#">July 2013</a></li>
<li><a href="#">June 2013</a></li>
<li><a href="#">May 2013</a></li>
<li><a href="#">April 2013</a></li>
</ol>-->
</div>
<div class="sidebar-module">
</div>
<div class="sidebar-module">
<h4>Elsewhere</h4>
<ol class="list-unstyled">
<li><a href="http://github.com/LottaJavaMike">GitHub</a></li>
<li><a href="https://twitter.com/ContemplateTech">Twitter</a></li>
</ol>
</div>
</div><!-- /.blog-sidebar -->
</div><!-- /.row -->
</div><!-- /.container -->
<footer class="blog-footer">
<p>Blog template built for <a href="http://getbootstrap.com">Bootstrap</a> by <a href="https://twitter.com/mdo">@mdo</a>.</p>
<p>
<a href="#">Back to top</a>
</p>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> -->
<!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> -->
</body>
</html>
感谢所有帮助或建议!
答案 0 :(得分:2)
当我查看您的页面并导航到源代码中指定的位置(http://mike.shea.sdf.org/js/jQuery-2.2.1.min.js)时,我也会收到404错误。
现在,我可以导航到您的helper.js
文件,它似乎具有相同的路径,因此您需要三重检查jQuery文件的命名。
此外,(作为旁白)正如我在评论中提到的,您在链接(/
)中有一个前导斜杠到jQuery文件。这意味着js文件夹是服务器根目录的子文件夹,可能与您谈论的HTML文件夹的子文件夹不同。从链接中删除正斜杠,并确保js
文件夹是HTML文件所在文件夹的子文件夹。