如何 return 从 Node.js 到 Angularjs 的成功或失败代码

How to return a success or fail code from Node.js to Angularjs

我正在使用 Angularjs 构建我的网站,并且正在使用 Node js 和 express 对其进行测试。因此,我可以发送一个 json 项目,其中包含联系页面表单中的信息。但是,我不知道如何 return 从 Node.js 到 Angularjs 的成功或失败代码重定向到感谢页面。此外,我需要知道如何将信息发送到我的电子邮件并将其保存到数据库以及如何为表单添加令牌。我知道我正在使用 MEAN 堆栈。我学习更好看。

这是我的节点 js:

var express = require('express');
var app = express();
var formidable = require('formidable');

app.use(express.static(__dirname + '/public'));    // navigate to where the app reside

app.get('/', function (request, response) {
    response.redirect('Index.html');
});

app.post('/Contact', function (request, response) {
    var frm = new formidable.IncomingForm();
    frm.parse(request, function(err, formData){
    var Name = formData.Name,
        Email= formData.Email,
        Message = formData.Message;
        response.writeHead(200, { "Content-Type": "application/json" });
        response.end("{'status:' 200}");
    });
});
var port = 8080;
app.listen(port);
console.log('Listening on port:  ' + port);

这是我的 Angularjs:

$scope.submit = function () {
        console.log('Im in the controller');
        console.log($scope.formData);       
        $http({
            method  : 'POST',
            url     : '/Contact',
            data    : $.param($scope.formData), 
            headers : { 'Content-Type': 'application/json' } 
        }).success(function(result, status, headers, config) {
                console.log(result);
            if(result.status == "???"){
                redirectTo: '/Thnkyu';
            }
        }).error(function(result, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
            console.log(result);
        });
    }

当我提交表格时;控制台显示:TypeError: Cannot read 属性 'protocol' of undefined 在它显示之前:ERR_CONNECTION_REFUSED 因为我在设置 headers 和数据之前有 url 部分.

问题是我使用 angularJs $http 依赖项,如上所示;但是,它没有用。所以,我像这样使用 $http 依赖:

$scope.submit = function () {
        console.log($scope.formData);
        $http.post("/contact", $scope.formData)
        .success(function(reponse){
            if(reponse.status == 200)
            console.log('im in')
            $location.path('/thnkyu');
        });

服务器的响应是这样的:

...
if(!eor){
        console.log(eor);
        response.json({status: 200});
    }