-
-
Notifications
You must be signed in to change notification settings - Fork 316
Restler 3: Cross Domain or Explorer Not Sending PUT, PATCH, DELETE etc..
Arul- edited this page Feb 10, 2013
·
3 revisions
When Using Restler 3 for APIs that need to be supported cross domain. You can place these items in the beginning of your php file to allow Cross Origin Requests.
<?php //index.php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, PATCH, DELETE');
header('Access-Control-Max-Age: 1000');
if(array_key_exists('HTTP_ACCESS_CONTROL_REQUEST_HEADERS', $_SERVER)) {
header('Access-Control-Allow-Headers: '
. $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
} else {
header('Access-Control-Allow-Headers: *');
}
//continue with rest of your index.php
Access-Control-Allow-Origin: *
: allows any domain to request your api
Access-Control-Allow-Methods
: Allows any of the listed methods to be sent to your api
Access-Control-Max-Age: 1000
: sets wither the browser Caches the Result So it always requests a new copy after 1000 seconds