Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS将数据发布到nodeJs/Sequelize_Javascript_Angularjs_Node.js_Express_Sequelize.js - Fatal编程技术网

Javascript AngularJS将数据发布到nodeJs/Sequelize

Javascript AngularJS将数据发布到nodeJs/Sequelize,javascript,angularjs,node.js,express,sequelize.js,Javascript,Angularjs,Node.js,Express,Sequelize.js,我正在用Nodejs/Sequelize和AngularJs创建一个电子商务网站 事实上,我有这个首发 在我的项目中,我有两个文件夹: 客户端(包含AngularJS初学者文件夹) 服务器(其中包含my Server.js 我想注册一个用户,我得到了我的“registeredView.html”和一个表单: <form ng-submit="submit()"> <input type="text" name=firstname ng-mod

我正在用Nodejs/Sequelize和AngularJs创建一个电子商务网站

事实上,我有这个首发

在我的项目中,我有两个文件夹:

  • 客户端(包含AngularJS初学者文件夹)

  • 服务器(其中包含my 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>
在我的“server.js”上,我试图得到这样的帖子:

    .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)
        })
    }
}]);
app.get('/registered', function (req, res) {
console.log(req.body)
res.end();
}))

但是它不起作用

我怎么了?有什么建议吗?
我需要你们的帮助:)

如评论中所述,有三个明显的问题:

  • 您的服务器需要的是
    get
    ,而不是
    post
    ,将
    app.get('/registed'…)
    更改为
    app.post('/registed'…)


  • 这里缺少一个点:
    $http.post('/registed',$scope.user)然后(函数(响应){
    ,在结束
    之间)
    然后

  • 您需要标记要注入的
    $http
    ,就像
    $scope
    一样-将
    ['$scope',function($scope,$http)
    更改为
    ['$scope','$http',function($scope,$http)


为了能够对发布的数据进行处理,您应该签出。需要后,您可以执行以下操作-
app.use(bodyParser.json())
。然后您应该可以访问
req.body
,其中应该包含您的用户解析为javascript对象的内容。

是的,我刚刚注意到它并尝试更改为app.post,但它仍然不起作用。您在这里缺少一个点:
$http.post('/registed',$scope.user),然后(函数(响应){
,在关闭
之间)
然后
。如果这对我们没有帮助,你必须给我们一个更具体的想法,说明什么不起作用,是否有错误?即使我在app.post request.body中获得了数据,我如何处理数据?@UncleDava Oops IllFixthat@UncleDava我修复了它,得到了TypeError:无法读取未定义的属性“post”