updated show how work. answer accepted below didn't show code, ended in comments. simplicity, i've shown correct code here (my original code had 3 errors).
i'm using node.js express , handlebars. having trouble updating particular div sending data. worked.
inside view directory have: index.handlebars, view1.handlebars, temp.handlebars.
inside view1.handlebars, have button
:
<button type="button" id="btn-here" data-id="{{data.uniqueid}}"><a href="../update_this">update this</a></button>
and div
:
<div id="sectional"> {{> partial}} </div>
and when clicks button
, want update sectional div
. use jquery so:
$('#btn-here').on('click', function(event) { event.preventdefault(); var id_num = $(this).data('id'); //id_num correct $.get("/temp/" + id_num, function(res) { var updated_html = res; $('#sectional').html(updated_html); }); });
i allow jquery find temp.handlebars file via:
router.get('/temp/:id', view1.showstuff);
and inside view1.showstuff function:
showstuff: function(req, res) { res.locals.model = model; res.render('temp/' + id, {layout: false}); };
this sends along view data , updates view specified in jquery call.
thanks user below!
you either need router handler follows
app.get('/temp.html', function (req, res, next) { res.render('temp', {layout: false}); });
or place temp.html in public folder can't use {{> partials}} not processed view engine