Skip to content

Instantly share code, notes, and snippets.

@brunojppb
Created December 16, 2016 17:13
Show Gist options
  • Save brunojppb/7a1a4ae8c313ff980ccf9f444801b95e to your computer and use it in GitHub Desktop.
Save brunojppb/7a1a4ae8c313ff980ccf9f444801b95e to your computer and use it in GitHub Desktop.
fetch('/users', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')},
credentials: 'same-origin',
body: JSON.stringify( { id: 1, name: 'some user' } )
})
.then(function(data) {
console.log('request succeeded with JSON response', data)
}).catch(function(error) {
console.log('request failed', error)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment