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

257
Vistas
Can't read data in node.js from a Ajax POST request

I need help with a very simple problem, but which for some reason I can't solve. I have a ajax post request that send data to a node.js server. From the server side, data seems to be received, but I am not able to retrieve the data fields.

Extract from the Client side:

function validateUser() 
{   
      $.ajax({
      type: "POST",
      url: "/authAjax",
      data: {
        username: "myusr",
        password: "mypsw"
      },
      success: function( result ) {alert("OK");},
      error: function( result ) {alert("ERR");}
    });
}

Extract from the Server side (node.js):

app.post('/authAjax', function(req, res)
{
    req.on('data', function (chunk) {
        console.log(req.body);      // not working
        console.log(req.username);  // not working
        console.log(req.data);      // not working
        res.send("200");            
    });
});

The res.send("200"); is executed, but I have no chance to get the passed username and password values. Could someone give any hint here?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

These were missing on the node.js side:

 app.use(express.json());

And the data is accessible with:

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