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

242
Vistas
Using ajax to convert inputs into JSON and POST to api

I am facing problem with understanding how input from tag can be converted in JSON and then posting it to my api.

My Frontend code is

<div>
    <form className="AddMentor">
      <table>
        <tr>
          <td> <label>MentorID<input type="text" name="MentorID" /></label> </td> 
          <td> <label>MentorName<input type="text" name="MentorNAME" /></label> </td>
          <td> <label>MentorEMAIL<input type="text" name="MentorEMAIL" /></label> </td> 
          <td> <label>MentorPH<input type="text" name="MentorPH" /></label> </td>
          <td> <label>MentorLINKEDIN<input type="text" name="MentorLINKEDIN" /></label></td>
          <td> <label>MentorPM<input type="text" name="MentorPM" /> </label> </td>
        </tr>
      </table>
    
    <button  type="submit" id="save">Add Mentor</button>
    </form>
</div>

And MY api code is

//ADD MENTOR API
router.route('/MentorEle').post((request,response)=>{

    let Mentor = {...request.body}

    dboperations.addMentor(Mentor).then(result => {
       response.json(result);
    })
})

I tried this for converting it into JSON and POSTING to my api

$(document).on('click', '#save', function(event) {
    event.preventDefault();
    var data = $('tr').map(function() {
        var obj = {};
        $(this).find('input, select').each(function() {
            obj[this.name] = $(this).val();
        });
        return obj;
    }).get();
    
    console.log(JSON.stringify(data));
});

It didn't work unfortunately, I faced several errors and the current error is

Module not found: Error: Cannot find file: 'node-jquery.js' does not match the corresponding name on disk: '.\node_modules\jquery\lib\jQuery'.

please anyone help me with this code or ajax approach of it

over 4 years ago · Santiago Trujillo
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