doSomethingAsynchronouslyAndReuturnPromise()
.then(result => transformTheResult(result))
.then(function callMeWhenReady(finalResult) {
console.log("Got the final result: " + finalResult);
})
.catch(failureCallback);
const promise = new Promise((resolve, reject) => {
resolve("value")
});
promise.then((result) => console.log(result));
const promise = Promise.resolve("value");
promise.then((result) => console.log(result));
function fetchData(url) {
fetch(url)
.then(response => response.json())
.then(data => console.log("Got the data: " + data))
.catch(console.log("Can't fetch data");
}
async function fetchData() {
try {
const response = await fetch(url);
const data = await response.json();
console.log("Got the data:", data);
} catch(error) {
console.log("Can't fetch data")
}
}
async function fetchData() {
try {
const data = await(await fetch(url)).json();
console.log("Got the data:", data);
} catch(error) {
console.log("Can't fetch data")
}
}
Download this page and resolve all TODOs.
Download this page and resolve all TODOs.
access-control-allow-methods: GET, OPTIONS
access-control-allow-origin: *
Cross-origin resource sharing (CORS) is the SELinux of the Web. You really want to do the right thing but it only works when you: "Access-Control-Allow-Origin", "*"
Download this page and resolve all TODOs.