CORS in short
A browser only lets your page read a reply from another site if that site allows it. The fix is on the server.
AJAX · CORS in shortBeginner
// 1) Same site: no CORS needed.
fetch('/api/items');
// 2) Another site: the OTHER server must send Access-Control-Allow-Origin.
fetch('https://api.example.com/items', { mode: 'cors' });
// 3) Send cookies to another site (server must allow credentials and a fixed origin):
fetch('https://api.example.com/me', { credentials: 'include' });
// PHP on api.example.com:
// header('Access-Control-Allow-Origin: https://www.mysite.com');
// header('Access-Control-Allow-Credentials: true');corsoriginheaderscredentials