Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Res.redirect() loads as a fetch instead of redirecting?

I have a simple fetch that happens after clicking a button to like a post:

function like(post_id){
    fetch(`/like/${post_id}`);
}

router.get('/like/:post_id/', authController.isLoggedIn, async (req, res, next) => {
  try {

    //liking

    req.flash("flash", 'You liked the post!');
    return res.redirect('back');
  }
  catch{
    req.flash("flash", 'Like failed :(');
    return res.redirect('back');
  }
});

In theory this should do its thing and then redirect back to the same page with the flash message.

Instead of doing that it loads the page with the fash message as afetch request I never called for!

It should reload the page to act/terrain/... not load it on the side. What's my problem? Do I need to end the fetch somehow before redirecting?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The mistake is using fetch in the first place. This is how I got it to work:

function like(post_id){
    document.body.innerHTML += `<form id="jsForm" action="/like/${post_id}" method="GET"><input type="hidden" name="a" value="a"></form>`;
    document.getElementById("jsForm").submit();
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!