let klantInfo = { Voornaam: voornaam, Achternaam: achternaam, Wachtwoord: myWachtwoord, EmailAdres: email, } let SendData = (ev) => { ev.preventDefault(); if (inputSucceeded) { window.onload = function() { postRequest(); } function postRequest() { const messageHeaders = new Headers({ // (1) 'Content-Type': 'application/json' }) fetch(apiUrl, { method: 'POST', body: JSON.stringify(klantInfo), headers: messageHeaders }) .then(function validateResponse(res) { return res; }) .then(function readResponseAsText(response) { return response; }) .then(function logResult(result) { return result; }) .catch(function logError(error) { return error; }); } function readResponseAsText(response) { console.log(response.text()); // (1) } } else { alert("Niet alle tekst zijn gevuld"); return; } } btnRegisteren.addEventListener('click', SendData)