Dranier
Dranier

Reputation: 321

Reload once Post Function is Complete

How to reload the page after pressing a button with a POST function?

app.post('/upload', upload.single("file"), (req, res) =>{
// res.json({file: req.file});
res.redirect("/");
window.location.reload();
})

I have tried window.loaction.reload() and it does not work

<form action="/upload" method="POST" enctype="multipart/form-data">
  <span class="input-group-btn">
    <span class="btn btn-success" onclick="$(this).parent().find('input[type=file]').click();">
      <span class="glyphicon glyphicon-search"></span> 
      Browse
    </span>
    <input name="file" onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());" style="display: none;" type="file">
    <button type="submit" class="btn btn-primary" onclick="popup">
      <span class="glyphicon glyphicon-upload"></span>
       Upload
    </button>
  </span>
</form>

This is the form that has the POST function.

The page is located is a branch page from the main page

:)

Upvotes: 2

Views: 80

Answers (1)

sheeldotme
sheeldotme

Reputation: 2503

To accomplish this you can do:

app.post('/upload', upload.single("file"), (req, res) =>{
// res.json({file: req.file});
    const url = req.header('Referer') || '/';
    res.redirect(url);
})

Upvotes: 2

Related Questions