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

107
Views
Cómo actualizar la página después de obtener la solicitud POST

Estoy creando una sala de chat simple y espero que la página se actualice cuando ingreso un mensaje en un cuadro de texto y presiono Intro.

La sala está recibiendo mensajes de una URL, pero tengo que volver a cargar la página para ver mi nuevo mensaje cada vez que lo publico.

¿Cómo muestro estos mensajes sin tener que recargar la página?

buscar OBTENER:

 fetch('https://curriculum-api.codesmith.io/messages', { 'method': 'GET' }) .then(response => response.json()) .then(data => addText(data))

obtener PUBLICACIÓN:

 textBox.addEventListener('keydown', (e) => { if (e.code === 'Enter') { const func = async function postReply() { const currentDate = new Date() const message = textBox.value; textBox.value = '' return await fetch('https://curriculum-api.codesmith.io/messages', { method: 'POST', body: JSON.stringify({ 'message': message, 'created_at': currentDate.toUTCString(), 'created_by': 'Nate & Dewey' }) }) .then(response => response.json()) // .then(json => addText(json.message)) } func() // $('#result').load('https://curriculum-api.codesmith.io/messages'); } })

función addText() (utilizada por GET)

 function addText(data) { let messageNum = 0 let current = data[messageNum] while (current) { const text = document.createElement('div'); border.appendChild(text); text.innerText = current.message + ' (' + current.created_by + ')' messageNum++ current = data[messageNum] } }
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!