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

216
Vistas
getting form data with FormData()

I hope the week has seen you all well and you're all gearing up for a great weekend. I've had to take up relearning of js and new learning of ajax recently and have a simple question I can't seem to resolve.

Take this sample form here ->

<form action="", method="post", onsubmit="return submitData(this)">
    First Name: <br>
    <input type="text" name="firstname"> <br>

    Last Name: <br>
    <input type="text" name="lastname"> <br>

    Age: <br>
    <input type="text" name="age"> <br>

    <input type="submit" id="buttonOne" value="Submit">
</form>

I've been passing the morning familiarizing myself with XMLHttpRequest() and FormData() classes and have the following super simple snippets

function submitData(fdata) {
    var formData = new FormData(fdata);

    for (var pair of formData.entries()) {
    console.log( pair[0] + ' - ' + pair[1] );
    }   
}

AND

var formData = new FormData();
formData.append('key_1', 'First value');
formData.append('key_2', 'Second value');
formData.append('key_3', 'Third value');

for (var pair of formData.entries()) {
    console.log( pair[0] + ' - ' + pair[1] );
}

The bottom one, where I create the form data programatically displays the data in console properly. The top one where I try to pull the data from the form does not work. Could someone break down what is happening here and point out the errors in my thinking please. Thank you

about 4 years ago · Juan Pablo Isaza
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