Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

can jade display a new value without refreshing the page?

can jade display a new value without refreshing the page?

Problem

app.get('/', function (req, res) {
    res.render('home.jade', {
        results: req.session.value
    });
});

What i would like know is whether i can use Jade to display req.session.value in the html when it has been given a value after i have triggered an event without refreshing the page.

    script
        function sendRequest() {
            var socket = io.connect();
            socket.on('value set', function(data){
            //jade code goes here
            });
           //i gave query a value here
        socket.emit('fire event', query);
        }
Problem courtesy of: wiel

Solution

"jade" can't do anything to dynamically update your page, the end result of a jade template is static html. If you want to update the page on that 'value set' event from socket.io you'll need to just use javascript, grab the element, and update it's value. Whatever client-side javascript library you're using should make this simple enough.

Solution courtesy of: Brad Harris

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

can jade display a new value without refreshing the page?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×