简体   繁体   中英

nodejs res.render local variable

i've been doing some work on how to display the correct things depend on the user's choice.

To be more specific, imagine a course page which allow you to see which quiz belong to which course .

On the course page, the quiz display will be hyperlinks with href such as: href='http:localhost:3000/quizs?getQuiz= theQuizName '

When select the link, it go to another page which display the selected quiz a quiz page . And theQuizName is the name of the selected quiz .

All the links will go the the same page , the only thing that changes is theQuizName to change the quiz displayed on the quiz page

in the server side, i intend to send theQuizName from the url ( http://localhost:3000/quizs?getQuiz=MyFirstQuiz ) to the client side like so:

app.get('/quizs', function(req, res){
    var toClient = req.params('getQuiz');
    res.render('quizess.ejs', {quizToDisplay: toClient});
});

But the problem is that i don't know where the local variable (quizToDisplay: toClient) is sent to nor how to get it.

So that i can based on the sent data (quizToDisplay: toClient) to change the quiz to display on the quiz page (quizess.ejs) with the client side javascript

在任何地方的<%= quizToDisplay %>上使用<%= quizToDisplay %>来打印变量。

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