I get the following error from an ajax request in Firefox:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.example.org/php/save.php. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
I tried to find out why this is happening. It is strange since
- the script works totally fine on my subdomain on the same server
- the file accessed is on the same server
I also tried
xhttp = new XMLHttpRequest({mozSystem: true});
as suggested here: https://stackoverflow.com/a/22392080
But that did not help either.
I am using the following command to open the request:
xhttp.open('POST', '/php/save.php', true);
I found a number of other solution for when the file is on another server:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
But I don't see why I should do this if the file is actually on the same server...
Edit
I removed the following two lines from my .htaccess
file and now it works.
RewriteCond %{HTTP_HOST} !^www\.example\.org$ [NC]
RewriteRule .? http://www.example.org%{REQUEST_URI} [R=301,L]
Though I am not sure why... maybe the adding of www.
works like moving to a subdomain?
What would I have to add to my .htaccess
file to get it to work with ajax and the rewrite?