Skip to content

Instantly share code, notes, and snippets.

@davehax
Last active May 23, 2017 22:49
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/7383eae2f5fcff2721a05cb2bc6e6068 to your computer and use it in GitHub Desktop.
Save davehax/7383eae2f5fcff2721a05cb2bc6e6068 to your computer and use it in GitHub Desktop.
var myHeaders = new Headers({
'X-RequestDigest': document.getElementById('__REQUESTDIGEST').value,
'Accept': 'application/json; odata=verbose'
})
var myInit = {
method: 'GET',
headers: myHeaders,
credentials: 'include'
}
fetch(_spPageContextInfo.webAbsoluteUrl + "/_api/web", myInit).then(function(response) {
if (response.ok) {
return response.json();
}
else {
throw new Error('Network response was not ok.');
}
}).then(function(data) {
if (window.console) {
console.log(data);
}
}).catch(function(error) {
// Error handling code goes here
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment