Skip to content

Instantly share code, notes, and snippets.

@paulaleite
Last active July 19, 2020 02:53
Show Gist options
  • Save paulaleite/1ee5a1d0c56d4f9c9e73c3ca92965e1d to your computer and use it in GitHub Desktop.
Save paulaleite/1ee5a1d0c56d4f9c9e73c3ca92965e1d to your computer and use it in GitHub Desktop.
const handleFormSubmit = event => {
event.preventDefault();
const form = document.getElementById('contactForm'); // 1
const formData = new FormData(form).entries(); // 2
var xmlhttp = new XMLHttpRequest(); // 3
var url = "https://<URL_website>/<caminho>"; // 4
xmlhttp.open("POST", url); // 5
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); // 6
xmlhttp.send(JSON.stringify(Object.fromEntries(formData))); // 7
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment