Skip to content

Instantly share code, notes, and snippets.

@evilnapsis
Created January 31, 2017 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilnapsis/87881a570b9bc56dcb4e59a23ca2088b to your computer and use it in GitHub Desktop.
Save evilnapsis/87881a570b9bc56dcb4e59a23ca2088b to your computer and use it in GitHub Desktop.
Formulario para enviar los datos via XMLHttpRequest
<!DOCTYPE html>
<html>
<head>
<title>Formulario Ajax</title>
</head>
<body>
<h1>Formulario Ajax</h1>
<form id="myform">
<label for="name">Nombre</label>
<input type="text" name="name" id="name" placeholder="Nombre" required><br>
<label for="lastname">Apellidos</label>
<input type="text" name="lastname" id="lastname" placeholder="Apellidos" required><br>
<label for="phone">Telefono</label>
<input type="text" name="phone" id="phone" placeholder="Telefono" required><br>
<label for="address">Domicilio</label>
<input type="text" name="address" id="address" placeholder="Domicilio" required><br>
<input type="submit" value="Enviar">
</form>
<script>
var form = document.getElementById("myform");
form.onsubmit = function(e){
e.preventDefault();
var formdata = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.open("POST","process.php",false);
xhr.send(formdata);
console.log(xhr.responseText);
form.reset();
}
</script>
<p>Powered by <a href="https://evilnapsis.com/" target="_blank">Evilnapsis</a></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment