Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 3 - CORS ?
#1

I'm trying to access a REST API but I keep getting the following in the console:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at /assets/ADMIN/data/search.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at "url to controller method". (Reason: CORS request did not succeed)

I've tried so many solutions from google and nothing seems to work.



Like adding this in the controller constructor, inside the method and on top of the page (above the controller class)

header("Access-Control-Allow-Origin: *");

header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS");

header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization");




I thought I would find a single answer to this problem, like "aha! you gotta do this to fix it" but that hasn't been the case.

Any ideas?
Reply
#2

MDN -> Reason: CORS header 'Access-Control-Allow-Origin' missing
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

This is an assumption. Based on what you provided it appears you are trying to access content on a domain which you have ownership. Access control allowed missing means the access control headers are not properly setup for the content to be accessed. Which I would assume means the framework in use is not setting the proper headers globally or you have not conifured them properly.

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Reply




Theme © iAndrew 2016 - Forum software by © MyBB