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

304
Views
PUT 404 (NO ENCONTRADO) y SyntaxError: token inesperado <en JSON en la posición 0

[PONGA 404 (No encontrado)] [1] [1]: https://i.stack.imgur.com/ugZng.png

Código del lado del cliente

 const confirmDeliver = (event) => { const newQuantity = inventory.quantity - 1; const updateQuantity = { newQuantity }; const url = `http://localhost:5000/inventory/${inventoryId}`; fetch(url, { method: "PUT", headers: { "content-type": "application/json", }, body: JSON.stringify(updateQuantity), }) .then((response) => response.json()) .then((data) => console.log(data)); };

Código del lado del servidor

 app.put("inventory/:id", async (req, res) => { const id = req.params.id; const updatedQuantity = req.body; const filter = { _id: ObjectId(id) }; const options = { upsert: true }; const updatedDoc = { $set: { quantity: updatedQuantity.quantity, }, }; const result = await inventoryCollection.updateOne( filter, options, updatedDoc ); res.send(result); });

¿Alguien puede decirme por qué me sale este error? ¿Como puedo resolver esto?

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

0

'Token inesperado <' significa que la respuesta devuelta no es un json válido. Este error puede deberse a una página html de error 404 respondida desde el backend.

El método de solicitud PUT es diferente de los métodos de solicitud GET, POST. Asegúrese de que el backend tenga un método de solicitud PUT con un punto final apropiado ' http://localhost:5000/inventory/your-inventory-id'.

Para probar rápidamente una conexión SUCCESS con el backend, simplemente devuelva una respuesta {} json vací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!