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

183
Views
el cuerpo de javascript está vacío en la API, pero no está vacío al enviar la solicitud

Estoy creando una solicitud de API simple en la que publico la información de la cesta de una venta en mi sitio de woocommerce en mi API. Desafortunadamente, el cuerpo de la llamada a la API sigue estando vacío. Claramente me estoy perdiendo algo realmente estúpido.

 var saleObjects = [] //Get the product names document.querySelectorAll("td.product-name").forEach(function(item){ var saleItem = {}; saleItem.title = item.innerText; saleObjects.push(saleItem); }); //Get the product prices document.querySelectorAll("td.product-total").forEach(function(item, i) { saleObjects[i].price = item.innerText saleObjects[i].commission = 0.05 saleObjects[i].url = window.location.hostname }); fetch(API_URL,{ method: "POST", mode: 'no-cors', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({saleObjects: saleObjects}) } ) .then(function(response) { return response.json(); }) .then(function(jsonResponse) { //console.log(jsonResponse) });

En mi backend estoy haciendo algo como esto:

 console.log("body"); console.log(req.body); console.log("saleObjects") console.log(req.body.saleObjects); var saleObjects = [] if (req.body.saleObjects == undefined) { return res.status(401).send(); }

He estado repasando esto varias veces sin éxito: Obtener: datos POST JSON

¿Estoy haciendo algo totalmente estúpido?

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!