Ajax to update partial view using express and jquery?

I would like to update a partial view using ajax. I would like to add new data to the HTML, but I would like to know if there is an easier way to do this.

I have a partial view that does this

  • every x in li x.name data

I pass data using! = Partial ('test', {data: data})

I want to call a function to re-view a partial view without reloading the page. and without adding append (...); Any ideas?? Or another way to do it ...

+4
source share
2 answers

First add only partial route, e.g.

app.get('/mypartial', function (req, res) { //compute data here res.render('mypartial', {layout: false, data: data}); }); 

Then load the new HTML by calling jQuery .get or .ajax on /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 .

+15
source

Use it. You can get a good solution.

 function ajaxRequest(url, succesCallBck, completeCallBck, errorCallBck)<br> { $.ajax({url: url type: "POST", dataType: "json", complete: completeCallBck, success: succesCallBck, error: errorCallBck }); } 
-2
source

All Articles