2
Hello. What I want to know is the best way to send data to the client and this data will be received through a function (which can be executed in a click).
In the example below I will render a page (I am using express in Node.js):
app.get('/exemplo', function (req, res) {
res.render('exemplo.html');
});
But if I want to send data to the rendered page, I will be required to use one url additional? As below:
app.get('/exemplo', function (req, res) {
res.render('exemplo.html');
});
var data = {...}
app.get('/exemplo/data', function (req, res) {
res.send(data);
});
Or you could do both using the same url? Or is there some other way to send data, for example user data to the page, using the expressJs.
Note: I do not use the pre-processor Jade.
From now on, thank you.
Can’t you just send a <script type...>var meuJson = { ... }<script> next to HTML? There’s probably a thousand simple ways to solve the problem, but I think the question is a little vague. Anyway, one thing is fact: qq URL that you provide pro JS from the client, the client can use as he wants to get the data that the JS would get. Another solution would be to concatenate JSON after HTML and split it into 2 separate strings later. You can only reply with more details.
– Bacco
@Bacco, look at my edition. See if it’s clearer.
– Samir Braga