enabling cors in codeigniter ( restserver by @chriskacerguis )

Try adding OPTIONS to the allowed methods. header(“Access-Control-Allow-Methods: GET, OPTIONS”); header(“Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding”); and return immediately when the request is method ‘OPTIONS’ once you have set the headers. if ( “OPTIONS” === $_SERVER[‘REQUEST_METHOD’] ) { die(); } See also this answer. Angular sends a W3C CORS spec compliant preflight request that will check for … Read more

HTTP OPTIONS error in Phil Sturgeon’s Codeigniter Restserver and Backbone.js

I encountered exactly the same problem. To solve it I have a MY_REST_Controller.php in core and all my REST API controllers use it as a base class. I simply added a constructor like this to handle OPTIONS requests. function __construct() { header(‘Access-Control-Allow-Origin: *’); header(“Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method”); header(“Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, … Read more