从angularjs控制器到Nodejs的HTTP发布

时间:2016-07-19 13:00:04

标签: javascript angularjs node.js

这是我的角度控制器代码

clientApp.controller('formCtrl',function($scope,$http){
    $scope.statuses = ["Active", "Inactive"];
    $scope.cluster = ["East Coast","West Coast","PayPal"]
    //when submit button is clicked 
    $scope.submit = function() {
           alert("Submit Clicked");
           $http.post('/clientPost', $scope.formData).success(function(response) {
                console.log('Data posted successfully');
            })

                    .error(function(data){
                            console.log('Error: ' + data);
                    });
    };
});

此代码从$ scope.formData中的前端表单中获取一组值,并尝试使用$ http.post将其传递给后端nodejs文件。

节点js - 服务器端控制器

app.post('/clientPost', function(req, res) {
alert("Posted successfully");
var cope = req.body.params;
var query = "insert into lv_billing.client (Client_ID, Client_Name, Status, Updt_Time, Updt_By, Updt_ID, Cluster) values ?"
alert(cope);

});

但是,我无法连接到nodejs

0 个答案:

没有答案
相关问题