I'm having a weird problem with AngularJS 1.08 and CORS on Firefox. My AngularJS looks like this:
var MyApp = angular.module('MyApp');
MyApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);
$http({
dataType : 'json',
url : 'http://api.example.com/restful',
withCredentials : true,
method: 'POST',
data : {val1 : 'Test'}
}).success(function(response) { console.log(response)}).error(function(response) { console.log(response)});
The PHP side looks like this:
header('Access-Control-Allow-Origin: '. $_SERVER['HTTP_ORIGIN'] );
header('Access-Control-Allow-Credentials: true' );
header('Access-Control-Request-Method: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: *,x-requested-with,Content-Type');
header('X-Frame-Options: DENY');
if(strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
//DO XYZ
} else if (condition) {
//DO DEF
}
This working fine on Chrome and Safari and on FireFox $_GET request works but not $_POST. On Firefox and Apache I get an Error 500 and on Nginx it exectues without the data, and throws an empty error message. Is there something wrong with my setup for CORS?