简体   繁体   中英

has been blocked by CORS policy: No 'Access-Control-Allow-Origin'

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?

As I read here , Maybe you need use:

Header add Access-Control-Allow-Origin "*"

Instead of:

Header set Access-Control-Allow-Origin "*"

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:

Header add Access-Control-Allow-Origin "example.com" //OR "localhost"

use this instead of esterik * Access-Control-Allow-Headers: Accept

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM