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

236
Views
Los datos de Fetch() no aparecen en el lado del servidor

Estoy enviando un fetch() simple a mi servidor de la siguiente manera:

 eo.put = function (state) { console.log('PUT:state', state); let _id = encodeURIComponent(state._id); const options = { headers: {'Content-Type': 'application/json'}, method: 'PUT', body: JSON.stringify(state) }; fetch("/articles/put/" + _id, options ) .then((response) => { console.log('RESPONSE', response); // you need to update the DOM here }) .catch((error) => { console.error("DEBUG: fetch/PUT error", error); }); }

y puedo verificar que el estado se complete con console.log().

Sin embargo; en el lado del servidor, req.body no está poblado y se muestra indefinido.

 // .. snip app.use('/articles', routes.articles); // .. snip // UPDATE OPERATIONS router.route('/put/:_id').put((req, res) => { const _id = req.params._id; const obj = req.body; /* ** ** req.body is empty ** */ debug && console.log('DEBUG: route: /articles/put : req.body', req.body); DBM.updateArticle(_id, obj).then(() => { }).catch((err)=>{ res.status(500).send("DEBUG: database internal error", err); }); res.end(); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Lo más probable es que necesite agregar un analizador de cuerpo

 const bodyParser = require('body-parser') // parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: false })) // parse application/json app.use(bodyParser.json()) // your routes...
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!