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

436
Views
Error: SyntaxError: token r inesperado en JSON en la posición 0 todas las operaciones de la base de datos en segundo plano van bien, entonces, ¿por qué recibo este error?

Obtención del token r inesperado en JSON en el error de posición 0.

Aquí está mi código:

 import React, { useEffect, useState } from 'react'; const AddInventory = () => { const [items, setItems] = useState([]); const [isReload, setIsReload] = useState(false); useEffect(() => { fetch("http://localhost:5000/inventory") .then((res) => res.json()) .then((data) => setItems(data)); }, [isReload]); const handler = (e) => { e.preventDefault(); const name = e.target.name.value; const email = e.target.email.value; const user = { name, email }; fetch("http://localhost:5000/inventory", { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(user), }) .then(response => response.json()) .then(data => { const newUsers = [...items, data] setItems(newUsers) setIsReload(!isReload) }) .catch((error) => { console.error('Error:', error); }); } return ( <div className='container mt-5'> <h4>this is add inventory {items.length}</h4> <form onSubmit={handler} action=""> <input className='m-2' type="text" name="name" id="" placeholder='name' /> <input className='m-2' type="text" name="email" id="" placeholder='email' /> <input className='m-2' type="submit" value="Add User" /> </form> { items.map(item => <li key={item._id}>Name:{item.name} Email:{item.email}</li>) } </div> ); }; export default AddInventory;

pero estoy tratando de entender qué está mal con mi código. Tal vez haya otra probabilidad de que falle la funcionalidad del lado del servidor que generalmente es responsable de generar y devolver el JSON en cadena.

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!