Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda