I am trying to send a form with "POST" method with AngularJS. I use $http to send it but it always return "Cannot POST" and 404 error. The route is correct and only happens if I execute my app via Grunt (sending by "GET" works perfect). The app has been built using Yeoman.
I think that it has to be a silly problem but I cannot make it work.
The view:
<form name="formLogin" ng-submit="login()">
<ul>
<li>
<label for="user">User</label>
<input type="text" id="user" name="user" ng-model="user">
</li>
<li>
<label for="pass">Password</label>
<input type="password" id="pass" name="pass" ng-model="pass">
</li>
</ul>
<input type="submit" value="Send">
The controller:
'use strict';
angular.module('myApp')
.controller('LoginCtrl', function ($scope, $http, $resource) {
$scope.login = function() {
var config = {
url: 'php/login.php',
method: 'POST',
data: {
user: $scope.user,
pass: $scope.pass
}
}; // configuration object
$http(config)
.success(function(data, status, headers, config) {
console.log('success');
if (data.status) {
// succefull login
} else {
// Wrong login
}
})
.error(function(data, status, headers, config) {
console.log('error');
});
};
});
I use Grunt with:
grunt server
Why happens that?
Thanks!