Enable cors from my local machine - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Enable cors from my local machine (/showthread.php?tid=78893) |
Enable cors from my local machine - Madsex - 03-23-2021 Hi, i have a server with a normal domain and codeigniter 3. To test a new project based on angular i would to do a query on DB server between Codeigniter. Particularly i have a controller with all function that i need in my ajax call from my local machine. When i do ajax call browser return in console this error: Access to XMLHttpRequest at 'https://xxxxx.it/xxxx' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. I have tried to add in my controller under parent:__constructor this headers: header('Access-Control-Allow-Origin: *'); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) { die(); } But unfortunatly not work. Then i have insert in my htaccess this: <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" </IfModule> But not work. Some one can help me to enable CORS on my codeigniter3 ? Thanks for help RE: Enable cors from my local machine - InsiteFX - 03-25-2021 You can add it to your .htaccess file in the root with index.php that's how I do it. Code: # Add Font Types Give that a try, take out what you do not need. RE: Enable cors from my local machine - Madsex - 03-26-2021 I have change my htaccess with your, infact img not works, have change url allowed with localhost:4200 (from my local machine). Nothing, same error RE: Enable cors from my local machine - InsiteFX - 03-26-2021 Show me your .htaccess file, so that I can see what it is doing. You can also read this. How to enable Cross-Site XMLHttpRequests (Cors) using .htaccess |