【发布时间】:2018-02-09 05:09:48
【问题描述】:
我正在使用 Nodejs/Sequelize 和 AngularJs 创建一个电子商务网站。
我实际上得到了这个开胃菜AngularJS starter。
在我的项目中,我有 2 个文件夹:
- 客户端(包含 AngularJS 入门文件夹)
- 服务器(包含我的 server.js
我想注册一个用户,我的“registeredView.html”带有一个表单:
<form ng-submit="submit()">
<input type="text" name=firstname ng-model="user.firstname" placeholder="firstname" required=" ">
<input type="text" name="lastname" ng-model="user.lastname" placeholder="lastname" required=" ">
<input type="email" name="email" ng-model="user.email" placeholder="Email Address" required=" ">
<input type="password" name="password" ng-model="user.password" placeholder="Password" required=" ">
<input type="password" name="confirm_password" ng-model="user.confirm_password" placeholder="Password Confirmation" required=" ">
<input type="submit" value="Register">
</form>
现在,感谢 $scope.user,我可以在“RegisteredController”中获取这些数据,但我不知道如何将这些数据发送到我的服务器。
我正在使用 express 模块,所以我尝试了这样的 $http.post :
.controller('RegisteredController', ['$scope', function ($scope, $http) {
$scope.submit = function () {
$http.post('/registered', $scope.user)
then(function (response) {
console.log("posted")
}).catch(function (response) {
console.error(response)
})
}
}]);
在我的“server.js”上,我试图得到这样的帖子:
app.get('/registered', function (req, res) {
console.log(req.body)
res.end();
});
但它不起作用..
我错了什么?一些忠告 ? 我需要你们的帮助:)
【问题讨论】:
标签: javascript angularjs node.js express sequelize.js