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

281
Views
Express res.redirect no redirige en la publicación

Tengo un pequeño problema con res.redirect();

He escrito una función que al hacer clic en el botón envía una solicitud de publicación al servidor y está funcionando. Pero cuando trato de usar res.redirect ("/"), me redirige a la ruta de inicio en el servidor, pero no sucede nada en el navegador.

Aquí está el código:

Una función que envía una solicitud de publicación.

 const sendData = () =>{ const title = document.getElementById('titleOfArticle').value; const textForPublish = document.getElementById('textForPublish').value; const data = { title, textForPublish } const options = { method: "POST", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify(data), } fetch('/compose', options); }

Código del servidor:

 const bodyParser = require("body-parser"); const ejs = require("ejs"); const posts = []; //array for all posts const homeStartingContent = "text 1"; const aboutContent = "text 2"; const contactContent = "text 3"; const app = express(); app.set('view engine', 'ejs'); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use(express.static("public")); app.get("/", (req,res) => { res.render('home', {homeContent: homeStartingContent}); console.log(posts); }) app.get("/about", (req,res) => { res.render('about', {aboutContent: aboutContent}); }) app.get("/contact", (req,res) => { res.render('contact', {contactContent: contactContent}); }) app.get("/compose", (req,res) => { res.render('compose'); }) app.post('/compose', (req,res) => { const post = { title: req.body.title, content: req.body.textForPublish }; posts.push(post); res.redirect('/'); });
about 4 years ago · Juan Pablo Isaza
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!