Reputation: 2682
It's the very famous browser error. I know it has been discussed a lot but I've noticed is a very generic error so I want to present my problem.
I am making simple requests (get,post) on a server where I have access. My browsers (chrome, firefox) give me Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at url (Reason: CORS header 'Access-Control-Allow-Origin' does not match 'null').
error.
When I use some of (hacking)plugins I get the responses fine.
What I've tried is to add on my back-end (on server):
header('Access-Control-Allow-Origin: *');
in index.php
file with no luck. Any other ideas ?
Upvotes: 3
Views: 26144
Reputation: 29
You can whitelist the blocked URL like:
script-src 'unsafe-inline' https: 'nonce-abcdefg' 'strict-dynamic'
Upvotes: 0
Reputation: 29
I have solved this issue.
// HTTP
define('HTTP_SERVER', 'http://domain name with www/');
// HTTPS
define('HTTPS_SERVER', 'http://domain name with www/');
Add you htaccess file
RewriteCond %{REQUEST_METHOD} OPTIONS RewriteRule ^(.*)$ $1 [R=200,L]
Upvotes: 1
Reputation: 675
There are several ways to do this. One way is the javascript way, which requires a callback and one example can be found here: Loading cross domain html page with AJAX
Another way is to utilize PHP's curl
functionality. Of course there are many ways to do this, but one method that works well for me is to:
Hope this helps, Adam
Upvotes: 0
Reputation: 63
I tried adding a chrome plugin "Allow-Control-Allow-Origin" after several tries with server side changes. Everything worked fine.
Upvotes: -2
Reputation: 677
Try adding
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
Upvotes: 6