Chapter 4: initial recipe samples

This commit is contained in:
Beth Griggs
2020-04-29 22:00:34 +01:00
parent 503edc4ec2
commit bcf782f7dc
59 changed files with 471 additions and 655 deletions
+30
View File
@@ -0,0 +1,30 @@
<form method="POST">
<label for="forename">Forename:</label>
<input id="forename" name="forename">
<label for="surname">Surname:</label>
<input id="surname" name="surname">
<input type="submit" value="Submit">
</form>
<script>
document.forms[0].addEventListener('submit', (event) => {
event.preventDefault()
let data = {
'forename': document.getElementById('forename').value,
'surname': document.getElementById('surname').value
};
console.log('data', data);
fetch('http://localhost:3000', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(function (response) {
console.log(response);
return response.json();
});
});
</script>