Enable cors from my local machine |
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
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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
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 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |