I am trying to obtain data from a JSON, in local mode I can make it work, I have to enable a CORS extension in chrome and that’s it.
Then when I have decided to upload the file to the server, on the server side with PHP, I enable the headers as follows
<?php
header("Access-Control-Allow-Origin: *");
?>
y tambien en el .htaccess de la siguiente manera:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
Access to XMLHttpRequest at 'https://www.siteExample.com/coins/151.json?hr=100' from origin 'https://meSiteExample.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
What else can I do?
2
Answers
As I read here, Maybe you need use:
Instead of :
in your .htaccess file.
Also Remember & pay attention
'*'
will enable CORS for all websites. and it has security risks. if you know your request coming from where , you can filter that by enter domain instead of'*'
.For example:
use this instead of esterik *
Access-Control-Allow-Headers: Accept