I would like to refresh a partial view using ajax. I kwow how to append the new data to the HTML, but I would like to know if there is a simpler way to do it.
I have partial view that does this
I pass the data using !=partial('test',{data:data})
I want to call a function to render the partial view again without reloading the page.. and without doing append( ... ); Any Idea?? Or other way to do it...
First, add a route for just the partial like
app.get('/mypartial', function (req, res) {
//compute data here
res.render('mypartial', {layout: false, data: data});
});
Then load the new HTML with a jQuery .get
or .ajax
call to /mypartial
.
Then use jQuery to replace the HTML of the parent element by doing
$('#idofparentelementofyourpartial').html(responseHTML);
See also my answer to this similar question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With