Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created June 2, 2020 01:34
Show Gist options
  • Save harrisonmalone/46f7c88246a71a640af7d6ceb1f7e297 to your computer and use it in GitHub Desktop.
Save harrisonmalone/46f7c88246a71a640af7d6ceb1f7e297 to your computer and use it in GitHub Desktop.
<!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