我正在尝试在我的快递js应用程序中添加Jquery-ui日期时间选择器但是我遇到了404错误。
<p>Date: <input type="text" id="datepick"></p>
<link rel="stylesheet" type="text/css"
href="stylesheets/jquery.datetimepicker.css"/ > <script
src="javascripts/jquery.js"></script> <script
src="javascripts/jquery.datetimepicker.js"></script>
<script type="text/javascript"> $(document).ready(function() {
$("#datepick").datepicker(); })
</script>
这是我的代码,静态文件位于公共文件夹下的公共javascripts和样式表中。
注意:快递代码
app.use(express.static(path.join(__dirname, 'public')));
EDIT1:控制台错误
GET /historicos/javascripts/jquery.datetimepicker.js 404 2.263 ms - 948
firefox错误
GET http://localhost:3000/historicos/stylesheets/jquery.datetimepicker.css [HTTP/1.1 404 Not Found 15ms]
GET http://localhost:3000/historicos/javascripts/jquery.js [HTTP/1.1 404 Not Found 28ms]
GET http://localhost:3000/historicos/javascripts/jquery.datetimepicker.js [HTTP/1.1 404 Not Found 26ms]
GET http://localhost:3000/historicos/javascripts/jquery.datetimepicker.js [HTTP/1.1 404 Not Found 3ms]
ReferenceError: $ is not defined historicos:25
答案 0 :(得分:0)
假设您有以下文件树:
/root
/public
/stylesheets
/javascripts
server.js
<强> /root/server.js 强>
app.use(express.static(path.join(__dirname, '/public')));
然后:
GET http://localhost:3000/stylesheets/jquery.datetimepicker.css
现在,如果您希望网址以 / historicos 作为前缀,则需要将其指定为 app.use()功能的第一个参数:
<强> /root/server.js 强>
app.use('/historicos', express.static(path.join(__dirname, '/public')));
现在你可以这样做:
GET http://localhost:3000/historicos/stylesheets/jquery.datetimepicker.css