Caveat: I am a front-end developer, I don't have much experience with servers.
I'm building an app with Angular 1.2 that pings an API on a different subdomain. The backend dev on the project is using nginx and has set it up to allow cross-domain requests by essentially forwarding the subdomain, or something similar, I believe. I can do an $http.get
request just fine, but when I try $http.post
I get the Access-Control-Allow-Origin error.
Here's the kicker: I can make the same request with jQuery's $.ajax
and it works just fine.
$.ajax({
type: 'POST',
url: 'http://api.mydomain.com/v1/customer/',
data: theData,
contentType: 'application/x-www-form-urlencoded',
//contentType: 'text/plain',
//crossDomain: true,
success: function(){
console.log("sent data via jquery");
}
});
Here's how I have Angular set up:
var myServices = angular.module("myServices", []);
myServices.config(function($httpProvider) {
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
});
And:
save: function(payload){
console.dir($http);
return $http.post('http://api.mydomain.com/v1/customer/', payload).then(function(result){
return result;
});
},
What am I missing?