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

224
Views
¿La solicitud JS fetch (POST) de front-end se envía como GET?

Entonces, esta solicitud de recuperación se llama en el botón Enviar.

Por alguna razón, en las herramientas de desarrollo, pasa como un GET. Probé la solicitud en Insomnia, y termina devolviéndome el sitio (el sitio del manillar)... y ninguno de los registros de mi consola nunca aparece (en el backend o en el frente)

Interfaz

 const newPostSubmit= async function(event) { console.log('didnt make it'); event.preventDefault() console.log('made it'); const title = document.getElementById('post-title').value; const content = document.getElementById('content').value; const response = await fetch(`/api/posts/`, { method: 'POST', body: JSON.stringify({ title, content }), headers: { 'Content-Type': 'application/json' } }); if (response.ok) { console.log('Post Success!') // document.location.replace('/dashboard'); } else { alert(response.statusText); } } document.getElementById('submit-post').addEventListener('submit', newPostSubmit);

Ruta de back-end que se utilizará

 router.post('/', checkAuth, (req, res) => { const body = req.body console.log(body); Post.create({ ...body, userId: req.session.userId }) .then(dbPostData => { console.log(dbPostData); res.json(dbPostData) }) .catch(err => { console.log(err); res.status(500).json(err); }); });

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

0

El problema estaba en mi HTML. La identificación de 'enviar publicación' se colocó en el botón, pero tenía que estar en el formulario en sí (el botón estaba dentro del elemento), razón por la cual la función nunca se ejecutaría

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!