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

362
Views
TypeError: res.json no es una función (no se pueden obtener datos de recuperación)

Estoy tratando de OBTENER una respuesta usando la API de búsqueda que no está atascada en un error como mencioné a continuación. Aquí está mi código

 const DefaultLayout = () => { let history = useHistory() const callHomePage = async () => { try { const res = fetch('http://localhost:4000/api/authenticate', { method: 'GET', headers: { Accept: 'application/json', 'Content-type': 'application/json', }, credentials: 'include', }) console.log(res) const data = await res.json() console.log(data) if (!res.status === 200) { const error = new Error(res.error) throw error } } catch (err) { console.log(err) history.push('login') } }

Error: TypeError: res.json no es una función Promesa {} muestra pendiente

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

0

const DefaultLayout = () => { let history = useHistory() const callHomePage = async () => { try { const res = await fetch('http://localhost:4000/api/authenticate', { method: 'GET', headers: { Accept: 'application/json', 'Content-type': 'application/json', }, credentials: 'include', }) console.log(res) const data = await res.json() console.log(data) if (!res.status === 200) { const error = new Error(res.error) throw error } } catch (err) { console.log(err) history.push('login') } }
about 4 years ago · Juan Pablo Isaza Report

0

Debe await la declaración de búsqueda y luego llamar al método .json de la respuesta.

 const res = await fetch(...) data = await res.json();

Leer más: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

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!