0
我正在使用Node + Express + Handlebars構建應用程序。我使用部分佈局來保存頭文件,並且它包含CSS,Bootstrap,jQuery等的所有CDN /引用。出於某種原因,並非所有的頁面都會加載各種引用和CDN。這裏是我的頭文件:CSS和Boostrap CDN沒有顯示在所有頁面上
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="images/flame.png">
<title>Metrics</title>
<link href="css/art-fonts.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/art-fonts.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/custom.css">
<link href="css/dashboard.css" rel="stylesheet">
<script src="js/ie-emulation-modes-warning.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="agile1.html"> <img src="images/coolmetrics.png" alt="CoolMetrics"/></a></div>
<div id="navbar" class="navbar-collapse collapse">
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Dashboard</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>
<li><a href="#">Reports</a></li>
<li><a href="#">Analytics</a></li>
<li><a href="#">Export</a></li>
</ul>
<ul class="nav nav-sidebar">
<li class="active"><a href="#">Projects <span class="sr-only">(current)</span></a></li>
<li><a href="agile1.html">Agile 1</a></li>
<li><a href="#">Agile 2</a></li>
<li><a href="#">Agile 3</a></li>
</ul>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="js/bootstrap.min.js"></script>
<script src="js/holder.min.js"></script>
</body>
下面是一個示例頁面,沒有CDN /引用將加載:
<!doctype html>
<html>
{{> header}}
<script type="text/javascript" src="/js/project.js"></script>
<div class="row placeholders">
<div class="container">
<h1>Project Details</h1>
<br>
</div>
</div>
</html>
在我的控制檯,網絡標籤返回404 /不是所有的CDN的發現和參考文獻。我的大約一半網頁有這個問題。另一半都很好。
這裏是一個可行的頁面的例子 - 所有CDN的&引用負荷:
<!doctype html>
<html>
{{> header}}
<script type="text/javascript" src="/js/home.js"></script>
<div class="row placeholders">
<h2 class="sub-header">Search for a Project</h2>
<div class="table-responsive">
<h1>Hi</
<div>
</html>
下面是我從服務器發送數據到客戶端:
hbs.registerPartials(__dirname + '/../views/partials');
hbs.registerHelper('json', function(context) {
return JSON.stringify(context);
});
module.exports = function (req, res) {
var context = {};
request('http://localhost:3000/api/single_project/' + req.params.id, function (err, resp1, body) {
context.project = JSON.parse(body);
request('http://localhost:3001/api/reports/' + req.params.id, function (err, resp2, body2) {
context.report = JSON.parse(body2);
//console.log(context.report[0]);
context.report.forEach(function(report) {
report.startdate = dateFormat(report.startdate, "yyyy-mm-dd");
report.enddate = dateFormat(report.startdate, "yyyy-mm-dd");
});
res.render('../views/project', context);
});
});
};
有人能幫忙嗎?
謝謝!
是的,jQuery顯然加載得很好。不,我沒有使用$ .ajax加載手柄部分。我正在使用'express-handlebars'包通過服務器呈現句柄代碼。 –
啊,好的。我們可以看到你的服務器代碼嗎? – Will
是的,只是更新了我的問題 –