rest - HTTP OPTIONS error in Phil Sturgeon's Codeigniter Restserver and Backbone.js -


my backbone.js application throwing http options not found error when try save model restful web service that's located on host/url.

based on research, gathered post :

a request send options http request header, , not trigger post request @ all.

apparently cors requests "cause side-effects on user data" make browser "preflight" request options request header check approval, before sending intended http request method.

i tried around by:

  • settting emulatehttp in backbone true.

backbone.emulatehttp = true;

  • i allowed allowed cors , csrf options in header.

    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");

the application crashed when backbone.emulatehttp line of code introduced.

is there way respond options request in codeigniter restserver , there other alternatives allow either disable request talking place?


i found this on github 1 solution. not sure if should use seems bit outdated.

i encountered same problem. solve have my_rest_controller.php in core , rest api controllers use base class. added constructor 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, delete");     $method = $_server['request_method'];     if($method == "options") {         die();     }     parent::__construct(); } 

this checks if request type options , if dies out return code 200 request.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -