0
我很新,所以我希望我提出正確的問題,並以正確的方式接近。我試圖從服務器獲取數據。我已經成功地將它傳遞給帕格頁面,但該頁面上的JavaScript無法訪問這些對象。這是服務器代碼。另外發布的是客戶端JavaScript,我無法訪問傳遞給帕格頁面的對象。如何從服務器路由獲取數據到JavaScript? Nodejs Express pug
router.get('/stockView', ensureAuthenticated, function(req, res, next){
var s = req.user.stocks;
var t = [];
// get array of stock symbols
for(var stock in s)
{
if (isNaN(parseInt(stock)))
{
}
else
{
s.push(req.user.stocks[stock].symbol);
}
}
//pull historic data from yahoo-finance
yahooFinance.historical({
symbols: ['AAPL','YHOO'],
from: '2012-01-01',
to: '2012-02-28',
period: 'd' // 'd' (daily), 'w' (weekly), 'm' (monthly), 'v' (dividends only)
}, function (err, quotes) {
if(err){
// do nothing
}else{
res.render('stockView', {title: 'Stock View', user: req.user, stocks: quotes, mystocks: s, tickers: t });
}
});
});
// *********javascript code in stockView.pug file****************
script(type='text/javascript').
$(function(){
var tickers = #{title};