Error about CORS when anuglar accesses my-json-server on stackblitz

2.6k views Asked by At

On stackblitz, I built an Angular project to access my-json-server mock server.
It's here.

Once clicking Send Request button, I got the following error on console:

Failed to load https://my-json-server.typicode.com/typicode/demo/posts/1: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://angular-http-test-cors.stackblitz.io' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

The error asks me to set the request's mode to 'no-cors'.
But how to achieve this?
Should I change the configuration on my-json-server? But how?
Could I just change my program?

References:
Requesting services from a different server (CORS)

UPTATE:20180314
I tried it today. Nothing is done, it can work now. Weird!

1

There are 1 answers

0
Farhad On

I tried your URL in chrome and that happened, you may try it again and if it fails just open up "Developer Tools" and in Network tab you see some of the requests failed, check mark the "Disable cache" and refresh, it shows up.