A
A
Alexander Koshelev2019-08-18 14:34:15
JavaScript
Alexander Koshelev, 2019-08-18 14:34:15

How to render the page and pass the data to the script?

Guys, good afternoon! Please tell me the following!
I have a router:

router.get('/', function(req, res) {
  News.findAll({
    raw: true,
    attributes: ['id', 'link'],
    where: { id: { [Op.gt]: 0 } },
  })
    .then((data) => {
      res.render('index', {
        auth: req.isAuthenticated(),
        data: data,
      });
      console.log(data);
    })
    .catch((err) => console.log(err));
});

1 with a get request, it renders the page
2 I need to transfer data from the data variable to the main page in the script tag
This code transfers the data available in data to the ejs template engine, for DOM visualization, but I need to be able to use the data from data in the script!
How can I correctly transfer data from the server to the client but in the script tag??
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Koshelev, 2019-08-18
@Xandr24

Damn, guys, I asked such crap, I just got confused that I didn’t open the data object as data[0].link and thought that it doesn’t work in the sript tag, sorry, the question is closed, figured it out!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question