Sunday, 4 June 2017

send data back to handlebars partial using express-handlebars

i building an application using express-handlebars.

i want to load a partial but send data back as well.

below is my logic on server.

var data = {
        days: [{
            day: 1,
            trips: [{
                imgage: 'https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg'
            }, {
                imgage: 'https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg'
            }, {
                imgage: 'https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg'
            }]
        },
        {
            day: 2,
            trips: [{
                imgage: 'https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg'
            }, {
                imgage: 'https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg'
            }, {
                imgage: 'https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg'
            }]
        }]
    };
    app.post('/currentday', function(req, res){
        console.log(req);
        res.render('partials/listDays', { data: data, layout: false });
    });

and here is how i'm calling it on the client. newDay is an object.

    $('#p2-dataContainer').load('/currentday', newDay);

I tried this but it just got stuck in a loop refreshing the content in the browser.

    app.post('/currentday', function(req, res){
        console.log(req);
        res.render('partials/listDays', data);
    });

so my question is how do i pass data to the partial with out the layout so it doesn't get stuck in a loop?



via angrymushroom

No comments:

Post a Comment