Send asynchronous browser requests with fetch, XMLHttpRequest, JSON, errors, and progressive UI.
Lessons
Learn how the browser enforces cross-origin rules.
Understanding CORS is easiest to learn by reading the example, changing it, and observing the result.
// The browser blocks cross-origin responses unless the server opts in.
const res = await fetch('https://api.other-site.com/data', {
mode: 'cors'
});
// The server must send, for example:
// Access-Control-Allow-Origin: https://your-site.com
const data = await res.json();Practice the Understanding CORS example in a small scratch file, then explain what changed and why.