【发布时间】:2016-04-03 20:53:00
【问题描述】:
我正在研究 Sails 并用它构建了一些简单的用户身份验证应用程序。路由写在 config/routes.js 中:
'GET /signup': {view:'signup'},
'POST /signup':'UserController.signup'
但是当我发出 POST 请求 localhost:1337/signup 时,我得到了响应(Chrome -> Network 显示)。不知道我在那里做错了什么。
你能帮帮我吗?
来自 api/controllers/UserController.js 的代码:
module.exports = {
signup: function(req, res){
console.log('Please, be in console');
}
}
角度代码:
angular.module('SignupMod').controller('SignupCtrl',['$scope', '$http', function($scope, $http){
console.log('Signup Controller Started');
$scope.runSignup = function(){
console.log('Signing Up ' + $scope.name);
//Submit to Sails Server
$http.post('/signup', {
name: $scope.name,
email: $scope.email,
password: $scope.password
})
.then(function onSuccess(response){
console.log('Success!');
})
.catch(function onError(err){
console.log('Error: ', err);
})
}
}])
【问题讨论】:
-
你是通过ajax注册还是直接发帖???
-
Ajax 发布请求(通过 Angular $http.post)
-
在网络中确实看到 post reqquest 或有 get 请求??
-
最好在此处添加您的角度代码!
-
角代码添加到问题。有谁知道我做错了什么?
标签: sails.js