D
D
Danil2015-01-21 10:01:51
JavaScript
Danil, 2015-01-21 10:01:51

How to update information on a page in nodejs?

Rendering the main page:

main.get('/', function(req, res) {
    res.render('main', data);
    res.end();
}

How can I update the information on this page now? For example, my data has changed and I want to render the page but with a new data. Upon attempt:
main.get('/newdata', function(req, res) {
    res.render('main', data);
    res.end();
}

I get:
Error: Can't set headers after they are sent.
I am using ejs. I would like to be able to somehow render the content of the page without reloading it and in parts. For example, if I have <%include main.ejs%> in my layout.ejs so that I can only re-render main.ejs

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Novikov, 2015-01-21
@Veneomin

I will disappoint you, but this problem cannot be solved by simple means. The render result is already sent to the client and you can't change it (although it's strange that such an error appears, these are 2 different answers). There are two solutions:
1) Look towards Meteor ;
2) Use websocket .
2nd I will explain: you have updated data (let's say data), you send a message to the client that there is updated data with a rendered result and using jQuery (for example) update the data on the page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question