下面是我的代码,我在变量中访问服务器对象,但在ejs中以Uncaught SyntaxError: Unexpected token <
的形式抛出以下错误
routerfile.js
var express = require('express');
var router = express.Router();
router.get('/', function (req, res) {
var obj ={"cn": "TH", "about": {"name": "thailand"}}
res.render('index.ejs', {res: obj});
})
util.js
var x = <%= JSON.parse(res) %>; //throws unexpect token error
index.ejs
<a href ="/en/<%=JSON.parse(res.about[name])%>">click me</a> // throws name not defined.