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

106
Views
Cómo agregar datos en la base de datos del servidor json

Esta es mi base de datos del servidor json.

 { "users": { "sarahedo": { "id": "sarahedo", "name": "Sarah Edo", "avatarURL": "https://pluralsight.imgix.net/author/lg/6f77d113-ea36-4592-814d-9d4acb32f231.jpg", "answers": { "8xf0y6ziyjabvozdd253nd": "optionOne", "6ni6ok3ym7mf1p33lnez": "optionOne", "am8ehyc8byjqgar0jgpub9": "optionTwo", "loxhs1bqm25b708cmbf3g": "optionTwo" }, "questions": ["8xf0y6ziyjabvozdd253nd", "am8ehyc8byjqgar0jgpub9"] }, }

Necesito agregar una nueva ID en "preguntas": ["8xf0y6ziyjabvozdd253nd", "am8ehyc8byjqgar0jgpub9"] pero no puedo acceder a ella en la búsqueda de URL.

Traté de verificar la URL en el navegador "HTTP://localhost:3000/users/sarahedo" Obtuve un objeto vacío por alguna razón {}

Quiero saber cómo puedo agregarle nuevos datos usando fetch POST.

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

0

La razón por la que obtiene un objeto vacío de http://localhost:3000/users/sarahedo es que ha definido incorrectamente sus datos en el archivo .json . Si corrige su archivo .json con los datos a continuación, verá su obj de usuario presionando http://localhost:3000/users/sarahedo en el navegador.

 { "users": [ { "id": "sarahedo", "name": "Sarah Edo", "avatarURL": "https://pluralsight.imgix.net/author/lg/6f77d113-ea36-4592-814d-9d4acb32f231.jpg", "answers": { "8xf0y6ziyjabvozdd253nd": "optionOne", "6ni6ok3ym7mf1p33lnez": "optionOne", "am8ehyc8byjqgar0jgpub9": "optionTwo", "loxhs1bqm25b708cmbf3g": "optionTwo" }, "questions": [ "8xf0y6ziyjabvozdd253nd", "am8ehyc8byjqgar0jgpub9" ] } ] }

Puede usar el siguiente código para agregar nuevos datos, usando fetch POST:

 async function postData(url = '', data = {}) { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) return response.json() }

Para obtener información más detallada sobre la obtención de POST, consulta esto: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options

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!