简体   繁体   中英

How to access the value of a variable from a javascript file in a jade file?

I have created a variable in my js file called loginCount.

This is how I have defined it:

var loginCount = 0; 

and this is how I am using it in this file:

function login(req, res) {
    var username = req.body.username;
    req.session.username = username;
    loggedInUsers[username] = LoggedIn;
    req.session.loginCount = loginCount;
    for (username in loggedInUsers){ 
        loginCount++;
        console.log("Login Count:", loginCount);
    }
    res.redirect("/users")
}

In my jade file I have tried

(#{loginCount} sessions)

but this doesn't work, it only shows ( sessions). Any insight?

Thanks!

in calling the jade file try:-

res.redirect("/users", {login: loginCount } );

now you can refer to the variable in jade :-

#{loginCount} // this will type the value of the variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM