我正在尝试使用express-validation创建验证,但是我的html页面中存在语法错误
如果有人能给我有关所遇到问题的线索,我将不胜感激。
SyntaxError: Unexpected token ) in /Users/johnmichaelquintero/Projects/rateme/views/user/signup.ejs while compiling ejs. If the above error is not helpful, you may want to try EJS-Lint: https://github.com/RyanZim/EJS-Lint
signup.ejs
<% if(hasErrors) {%>
<% for(var i=0; i < messages.length; i++) {%>
<div class="alert alert-danger">
<a href="" class="close" data-dismiss="alert" aria-label="close">
&time;
</a>
</div>
<%= messages[i] =%>
<% } %>
<% } %>
user.js:
app.get('/signup', (req, res) => {
var errors = req.flash('error'); //to get the error message
console.log(errors);
res.render('user/signup', {title: 'Signup || RateMe', messages: errors, hasErrors: errors.Length > 0});
});
答案 0 :(得分:0)
问题出在=%>
之后的messages[i]
。那里不应该有等号。
这应该有效:
<% if(hasErrors) {%>
<% for(var i=0; i < messages.length; i++) {%>
<div class="alert alert-danger">
<a href="" class="close" data-dismiss="alert" aria-label="close">
&time;
</a>
</div>
<%= messages[i] %>
<% } %>
<% } %>