Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/3ee1cc1f1ce30344bb960e0836bb3146 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/3ee1cc1f1ce30344bb960e0836bb3146 to your computer and use it in GitHub Desktop.
const form = document.getElementById('categoryForm')
form.addEventListener('submit', async (event) => {
event.preventDefault()
const name = document.getElementById('category')
const description = document.getElementById('desc')
const isActive = document.getElementById('is_available')
const data = {
name: name.value,
description: description.value,
isActive: isActive.checked
}
const body = JSON.stringify(data)
const init = {
method: 'POST',
body
}
await fetch('http://localhost:3000/categories', init)
form.reset()
window.location.href = './list_categories.html'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment