I am trying to make a simple POST request to
http://battle.platform45.com/register The server is setup to respond with
JSON. So from the command line:
$ curl --data '{"name": "Connor", "email": "[email protected]"}'
http://battle.platform45.com/register
successfully returns
{"id":"3118","x":1,"y":9}%
I try to do the same thing in angular:
app.controller('BattleshipCtrl', function ($scope, $http) {
$scope.game = {}
$scope.newGame = function(name, email){
$http.post("http://battle.platform45.com/register", {
name: name,
email: email
}).success(function(data, status, headers, config){
console.log('Success')
})
}});
with a simple view:
<input type='text' ng-model='game.name'><input type='text'
ng-model='game.email'><div class='btn btn-success' ng-click='newGame(game.name,
game.email)'>New game</div>
When I try to make the request I get an error:
OPTIONS http://battle.platform45.com/register 404 (Not Found)
angular.js:7962XMLHttpRequest cannot load
http://battle.platform45.com/register. No 'Access-Control-Allow-Origin' header
is present on the requested resource. Origin 'http://0.0.0.0:9000' is therefore
not allowed access.
How does the POST request go through with curl but not angular? What can I
do to successfully make the request with angular?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.