Why does JavaScript throw a CORS error, but Postman works fine?
Hi everyone! I'm a beginner frontend developer and I've been struggling with a problem for several days. I have a simple HTML/JavaScript site, and I'm trying to send a GET request to an external API (e.g., https://api.example.com/data). In the browser, I get an error: "No 'Access-Control-Allow-Origin' header is present on the requested resource". However, if I make the exact same request via Postman, everything works fine — the data comes through without any issues.
Here's my code:
```javascript
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```
I'm using a regular HTML file opened via file://, without a server. At first, I thought the problem was in my code, but Postman works! Why is that?