Konidoni Ravirr
Konidoni Ravirr

Reputation: 97

How can i refresh the current page using node js and express

I want to refresh my page using respone and here is my code:

app.post("/delete",function(req,res){
  res. <<-HERE I WANT TO REFRESH THE CURRENT PAGE USING "res."
})

If you think this question is stupid, please forgive me for that because iam a beginner :)

Upvotes: 2

Views: 3565

Answers (1)

Heiko Thei&#223;en
Heiko Thei&#223;en

Reputation: 17517

You can either redirect the browser to the page URL after the delete action:

app.get("/", function(req, res) {
  res.render("page.ejs");
});
app.post("/delete", function(req, res) {
  /* Carry out deletion */
  res.redirect("/");
});

or you can include the code that generates the page in both the GET and POST routes:

app.get("/", function(req, res) {
  res.render("page.ejs");
});
app.post("/delete", function(req, res) {
  /* Carry out deletion */
  res.render("page.ejs");
});

The important point is that, in both cases, the rendering of the page must take into account the prior deletion. Without you sharing more of your code, we cannot judge whether that works in your case.

Upvotes: 1

Related Questions