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.
Asked
Active
Viewed 1,435 times
1
-
Did you search on this error? this question is already asked overhere https://stackoverflow.com/a/20035319/8559155 – Ronald Haan May 06 '19 at 07:03
-
https://stackoverflow.com/questions/34748981/laravel-5-2-cors-get-not-working-with-preflight-options – Jagadesha NH May 06 '19 at 07:26
1 Answers
1
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:

Jagadesha NH
- 2,529
- 2
- 23
- 41
-
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. – Arun Pandian May 06 '19 at 07:45