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

298
Vistas
How to get access my data (username, password etc;) from FormData() into my express server

I'm currently trying to get the correct part of my data (the actual Username Value and Password Value by itself so I can extract it and save it to a value etc;) from FormData which I sent through a POST request to my express server but I can't seem to get it, it either comes back undefined when I try doing req.body.username OR req.body.name or prints all of my FormData when I do req.body:

'------WebKitFormBoundarymqLPaiCoVje2rgBB\r\nContent-Disposition: form-data; name': '"username"\r\n' +
'\r\n' +
'myNamePutInHere\r\n' +
'------WebKitFormBoundarymqLPaiCoVje2rgBB\r\n' +
'Content-Disposition: form-data; name="password"\r\n' +
'\r\n' +
'password123\r\n'

My Express Server: (NOTE: I also tried req.body.username but that didn't work either)

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }))

app.post('/', function(req, res) {
  res.send(req.body.name)
  console.log(req.body.name)
});

My JS to send it:

  const form = document.getElementById( "signUpForm" );
  const XHR = new XMLHttpRequest();
  const FD = new FormData( form );

  XHR.open( "POST", "http://localhost:3001/", true);
  XHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  XHR.send(FD);

My HTML form:

<form id="signUpForm" name="signUpForm">
          <div class="flex flex-col">
              <input type="text" name="username" placeholder="Username*" class="w-10/12 mr-2 h-7 border-2 mb-3 rounded-lg py-4 px-3 signupinput" required>
              <input type="password" name="password" placeholder="Password*" class="w-3/6 h-7 border-2 mr-2 rounded-lg py-4 px-3 signupinput" required>
          </div>
          <button class="w-40 h-10 text-white bg-main-blue hover:bg-blue-300 rounded-lg mt-12" type="submit" value="Submit">Create an account</button>
</form>

Any help would be great, Thankyou in advance

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

0

try arrow functions. log from your request at frontend first then log from whole req object on backend. then you can find body

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