I have a code where on error I return a status with an error message:
if (err){
res.render('page1', {status:2, msg:'Server Error : Probable unable to connect'});
return;
}
In my page1.ejs, I have coded the following way:
var status = <%= status %>;
alert ( 'The status = ' + status);
if( status == 2)
{
var msg = "'" + <%= msg %> + "'";
alert(msg);
}
OR
if( status == 2)
{
alert('"' + <%= msg %> + "'");
}
I am trying to get the value of status and msg - but since 'msg' exists as multiple words I am not able to find a way to capture complete strings as passed from NodeJS. Firebug shows error as:
SyntaxError: missing ) after argument list
alert('"' + Server Error : Probable unable to connect+ "'");
-------------------|
I am not an expert for EJS, but maybe this could work var msg = <%= msg %>; alert(msg);
? Or simply alert(<%= msg %>)
?
Try this:
alert('<%= msg %>');