Skip to content

Instantly share code, notes, and snippets.

@chulman444
Last active September 21, 2018 06:40
Show Gist options
  • Save chulman444/8cb7a35d05d886edb3f497746cda5b69 to your computer and use it in GitHub Desktop.
Save chulman444/8cb7a35d05d886edb3f497746cda5b69 to your computer and use it in GitHub Desktop.
I prefer async and await.
const myRequest = new Request(window.location.origin + "/test");
async function callRequest() {
res_p = await fetch(myRequest);
res_text = await res_p.text();
return res_text
}
callRequest().then(val => {
console.log(val);
});
const myRequest = new Request(window.location.origin + "/test");
fetch(myRequest)
.then(res => {
// console.log(res.json());
res.text()
.then(val => {
console.log(val);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment