Access to XMLHttpRequest at 'http://localhost:8080/socket.io/?EIO=3&transport=polling&t=MgBuvgw' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
-
Did you search on this error? this question is already asked overhere stackoverflow.com/a/20035319/8559155Ronald Haan– Ronald Haan2019-05-06 07:03:42 +00:00Commented May 6, 2019 at 7:03
-
stackoverflow.com/questions/34748981/…Jagadesha NH– Jagadesha NH2019-05-06 07:26:48 +00:00Commented May 6, 2019 at 7:26
Add a comment
|
1 Answer
Due to a security reasons browsers won't allow you to access other websites content until you specify with cors headers.
For more information on cors https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Fix:
quick solution: in public/index.php add the following headers
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type, X-Auth-Token, Origin, Authorization');
For better control and good practice use this package:
1 Comment
Arun Pandian
Hi, We used the command you shared but actually we faced the above issue only while connecting with web socket. Other than that we can be able to fetch the data.