form.addEventListener('submit', function(event) { event.preventDefault();
var data = new FormData(form);
var xhr = new XMLHttpRequest(); xhr.open('POST', '/api/register', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() { if (xhr.status === 200) { // Registration successful alert('Registration successful!'); } else { // Registration failed alert('Registration failed. Please try again.'); } };
xhr.send(data); }); })();
Credit and rights belong to OMG I Yoga