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

166
Vistas
How do you POST html form data with javascript

Im trying to POST data from a html form using javascript however on submission I believe no data is actually being sent because my alert is showing no data.

when i added an alert box

var jsonStr = JSON.stringify(FD);
      alert(jsonStr);

the output came up as "{}"

here is my full code below if anyone can spot my errora

<form class="emailentry" " method="post" name="myForm" id="myForm">
<label  for ="name">Name: </label><br>
<input type ="text"id="name" name="name: " ><br>
<label for ="emailad">Email: </label><br>
<input type ="email"id="emailad" name="emailad" ><br>
<input type= "submit" id="btn" name="submit" class="submitstyle">
</form>
<script>
    window.addEventListener( "load", function () {
  function sendData() {
    const XHR = new XMLHttpRequest();

    // Bind the FormData object and the form element
    const FD = new FormData( form );

    // Define what happens on successful data submission
    XHR.addEventListener( "load", function(event) {
        var jsonStr = JSON.stringify(FD);
      alert(jsonStr); // should present me the data i entered but it isnt
      alert("hi");
    } );

    // Define what happens in case of error
    XHR.addEventListener( "error", function( event ) {
      alert( 'Oops! Something went wrong.' );
    } );

    // Set up our request
    XHR.open( "POST", "ExampleUrl.ForStackOveerflow/post" );

    // The data sent is what the user provided in the form
    XHR.send( FD );
    

  }

  // Access the form element...
  const form = document.getElementById( "myForm" );

  // ...and take over its submit event.
  form.addEventListener( "submit", function ( event ) {
    event.preventDefault();

    sendData();
  } );
} );




</script>
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