javascript - Uncaught SyntaxError: Unexpected identifier: - 当使用 node express 的 response.locals 值时
问题描述
I was trying to access a variable added to node express's res.locals from index.hbs within a <script>
tag.
Express code
app.get('/', function(req, res) {
res.locals.settings = {active: true};
render(req, res, 'dist/index.hbs');
});
Using res.locals inside <script>
tag in hbs file.
<body>
....
rendered html
....
<script type="text/javascript">
somefunction(JSON.stringify({{{settings}}});
</script>
</body>
While loading the page, an error is thrown.
Uncaught SyntaxError: Unexpected identifier
解决方案
推荐阅读
- python - Django 当我创建一个用户时,创建了一个数据库
- javascript - 我的验证不适用于我的动态输入
- vba - 如何在 VBA 中刷新数据透视表
- docker - ./downloadFabric.sh 意外故障地址 0x183e42838582
- json - 何时使用类对象或 json 字符串进行 http 请求
- r - 错误对象“。” 使用管道时找不到
- node.js - NodeJS如何调试https.request和request.post输出之间的区别?
- c# - 在与其父级相同的窗口中查看子文件夹?
- excel - 相同的 Access 数据库在另一台计算机上产生错误
- javascript - 找不到本地存储的 json 文件