jquery not updating handlebars partial view correctly when submitting a form (express, node.js) -


i'm using node.js express , handlebars. having trouble updating particular div sending data.

i'll ask question 10' level first because maybe details unnecessary answer. when use href='blah' , set jquery function express right thing , updates div without updating whole page.

when use same code on <form method="post" .... however, instead drops layout, doesn't go jquery call, render entire handlebars page routed via express.

why these different , should doing instead?

if wasn't clear, here code:

inside view directory have: index.handlebars, view1.handlebars, temp.handlebars.

inside view1.handlebars, have form:

<form method="post" action="/update_this" enctype="multipart/form-data" data-id="{{data.uniqueid}}"> 

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 renders whole page , loses layout.handlebars file.

as stated, if instead have button href=... layout stays , renders perfectly. fact doing post request instead of get causes issue.

well jquery can load html directly element using $(<someelement>).load. here's docs: http://api.jquery.com/load/ basically, pointing route coming node server sends html, .load replace current html response.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -