Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
how to push or appand response data into web page

I am posting a comment with Axios (without refreshing page) client side to server. the comment saves successfully and sends saved data as a response. I want that response data shown on a web page after saving. I am not understanding how to do that, support me. here is my code into

    <script>
        const form = document.querySelector('.formPost');
 const pushComment = document.querySelector('#pushComments').innerHTML
const formEvent = form.addEventListener('submit', event => {
    event.preventDefault();
    const postId = document.querySelector('#postId').value;
    const adminId = document.querySelector('#adminId').value;
    const comment = document.querySelector('#comment').value;
    const commentData = {postId, adminId,comment};
 
   async function doComment(form){
 await axios({
    url:"/comment",
    method:'post',
    data:commentData,
}).then((responseData)=>{
   
  var  value = responseData.data
   document.getElementById('pushComments').innerHTML = value
    console.log(responseData.data)
})
 }
 doComment()
 function nulldata(){  
    const comment = document.querySelector('#comment').value=''
 }
 nulldata()
});

here sever side data

route.post('/comment', async (req,res)=>{

const user = req.user
    const comments = {
        postId:req.body.postId,
        admin: req.body.adminId,
        comment:req.body.comment,
        name:req.user.name,
        email:req.user.username
    }
    console.log( comments)
    const comment = await Comment.create(comments)
res.json({comment})

})

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're receiving a json response containing a comment-document from the server side.

Assuming you want to append the comment field from the response and pushComments is a simple <ul> you could simply do:

 const {comment} = responseData.data;
 const existingCommentsList = document.getElementById('pushComments').innerHTML;
 document.getElementById('pushComments').innerHTML = `${existingCommentsList}<li>${comment.comment}</li>`;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda