Hello Forum!
In CodeIgniter 4.2, when I make an AJAX call I get the following error:
net::ERR_FAILED 303
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This error ONLY appears when I use the website from my mobile. Neither on local nor on desktop I have any problem.
I have been searching for hours for information and have not been able to make any changes after trying everything I have found on the internet.
I tried this in htaccess
PHP Code:
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg|svgz|jpg|png|ico|font.css|css|js)$">
## un-remark this one for all access and remark out the one below it
#Header set Access-Control-Allow-Origin "*"
## Change this to your local host url. and https or http
Header add Access-Control-Allow-Origin: "https://yoursite.com"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header add Access-Control-Allow-Headers: "Upgrade-Insecure-Requests"
</FilesMatch>
</IfModule>
# Remove index.php from URL
RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.*)$ $1 [R=301,NS,L]
But with this code with the htacces, instead of sending the ajax, the page refreshes. The ajax call does not fail, but it does nothing.
I also created a CORS filter but it didn't work either, what could be happening to make it only appear on my mobile and how can I fix it?
Thank you very much for your time
EDIT: Ajax and PHP is in the same URL