2017-08-14 49 views
0

我有設置以下路線:傳遞數據,快速和EJS

router.get('/', function(req, res) { 
    res.render('index', {}); 
}); 

router.post('/application', function(req, res) { 
    res.render('application', {twitchLink : req.query.twitchLink}); 
}); 

我有兩個觀點正確設置。

這是我在「索引」已經得到了看法:

<form class="form-horizontal" action="/application", method="post", role="form"> 
    <input type="url" name="twitchLink" required> 
    <button class="btn btn-success">Submit</button> 
</form> 

提交這份表格,並帶我到應用程序視圖。

<script>var twitchLink = <%- JSON.stringify(twitchLink) %></script> 
<script>console.log(twitchLink)</script> 

這應該註銷我提交的鏈接,對不對? 不過,我得到以下兩行:

Uncaught SyntaxError: Unexpected end of input 
Uncaught ReferenceError: twitchLink is not defined 

回答

1

我認爲你需要把周圍<%- JSON.stringify(twitchLink) %>引號,像這樣:

var twitchLink = '<%- JSON.stringify(twitchLink) %>' 

在您的例子,它會出來爲:

var twitchLink = foo.bar.com 

你想要的是:

var twitchLink = 'foo.bar.com'