gruntjs - Yeoman, Grunt, AngularJS and error 404 on POST form -
i trying send form "post" method angularjs. use $http send return "cannot post" , 404 error. route correct , happens if execute app via grunt (sending "get" works perfect). app has been built using yeoman.
i think has silly problem cannot make 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!
i'm confused why get should work in case. grunt server serves static files app , .tmp directories , reference .php file relative. standard setup, ajax request php/login.php return plain php source code of file located in app/php/login.php, not want.
you want separate backend frontend , have php application in different location. either under different location (e.g. /api/login.php) or different host https://api.example.com/login.php. mixing yeoman application api isn't idea.
however, if forced keep them within 1 project, can use grunt-php start local php server gruntfile.
Comments
Post a Comment