Skip to content

Instantly share code, notes, and snippets.

@davehax
Last active June 7, 2017 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davehax/d2f6b094148f63c40c56512d2b9de7ab to your computer and use it in GitHub Desktop.
Save davehax/d2f6b094148f63c40c56512d2b9de7ab to your computer and use it in GitHub Desktop.
// POST request headers
var postHeaders = new Headers({
'X-RequestDigest': document.getElementById('__REQUESTDIGEST').value,
'Accept': 'application/json; odata=verbose',
'X-HTTP-Method': 'DELETE', // important - ensure DELETE is in all caps
'If-Match': '*'
});
// POST request options
var postOptions = {
method: 'POST',
headers: postHeaders,
credentials: 'include'
}
fetch(_spPageContextInfo.webAbsoluteUrl + "/_api/lists/getbytitle('Sample List')/Items(1)", postOptions).then(function(response) {
if (response.ok) {
// we all good
console.log('Response was ok!')
}
else {
throw new Error('Network response was not ok.');
}
}).catch(function(error) {
// Error handling code goes here
console.error(error);
alert('Error has been logged to the console');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment