我使用nodejs平台、html和jquery创建了一个简单的web页面。运行我的代码后,我得到了这个错误
http://localhost:3000/js/jquery.min.js加载资源失败:服务器响应状态为404(未找到)
任何建议的解决方案?
简单的解决方案,从CDN获取jQuery。
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
第二种解决方案是将nodejs配置为有一个公共文件夹,并在那里保存公共文件。(如果使用express
packace)
app.use(express.static(__dirname + "/js"));
并通过以下方式访问该文件:
我重新评论你有公共文件夹,那里保留你的javascript
和css
文件。
app.use(express.static(__dirname + "/public"));
在该文件夹中创建如下结构
--public
--css
-> example.css
--js
-> jquery-2.1.3.min.js
根据需要添加脚本
和链接
标记
<link href="/css/example.css" rel="stylesheet" />
<script src="/js/jquery-2.1.3.min.js"></script>
并像这样访问js/css文件
http://www.example.com/js/jquery.min.js
http://www.example.com/css/example.css