Created
June 2, 2020 01:34
-
-
Save harrisonmalone/46f7c88246a71a640af7d6ceb1f7e297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> </head> | |
<body> | |
<button>Add student</button> | |
<script> | |
document.querySelector('button').addEventListener('click', function () { | |
let data = { student: { name: 'Sarah', location: 'Sydney' } } | |
fetch('http://localhost:3000/students', { | |
method: 'POST', | |
body: JSON.stringify(data), | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
}) | |
.then((response) => response.json()) | |
.then((data) => console.log(data)) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment