我有一个代码,在出错时我会返回带有错误消息的状态:
if (err){
res.render('page1', {status:2, msg:'Server Error : Probable unable to connect'});
return;
}
在我的 page1.ejs 中,我按以下方式编码:
var status = <%= status %>;
alert ( 'The status = ' + status);
if( status == 2)
{
var msg = "'" + <%= msg %> + "'";
alert(msg);
}
或者
if( status == 2)
{
alert('"' + <%= msg %> + "'");
}
我正在尝试获取状态和消息的值 - 但由于“消息”作为多个单词存在,我无法找到一种方法来捕获从 NodeJS 传递的完整字符串。 Firebug 显示错误为:
语法错误:参数列表后缺少 )
alert('"' + Server Error : Probable unable to connect+ "'");
-------------------|
最佳答案
试试这个:
alert('<%= msg %>');
关于node.js - NodeJS : outputting a string using Express EJS Template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13229556/