从路由器到控制器没有得到任何响应

时间:2016-01-25 06:19:45

标签: angularjs node.js express passport.js

Post section image command prompt

login.controller

angular
    .module('app.pages.auth.login')
    .controller('LoginController', LoginController);

/** @ngInject */
function LoginController($http, $location)
{
    var vm = this;

    vm.submitPost =  function(userData){
        $http({
            url: 'http://localhost:7200/api/pages/auth/login',
            method: 'POST',
            data: userData
        }).then(function(res) {
            if(res.data.success){
                $location.path('/pages/profile');
                console.log(res.data.message);
                //vm.message=res.data.message;
            } else {
                //console.log(res.data.message);
                //vm.message=res.data.message;
                $location.path('/pages/auth/login');
            }
        }, function(error) {
            alert('here');
        });
    };   
}

api.js

router.get('/pages/auth/login', function(req, res) {
    console.log(req.flash('loginMessage'));
    res.render('auth/login/login.html', { message: req.flash('loginMessage') }); 
});

router.get('/pages/profile', isLoggedIn, function(req, res) {

    return res.json({
            success:true,
            //message: 'Login Success',
    })
    res.render('profile/profile.html', {user:req.user }); 
});
  

我没有从路由器到控制器得到任何响应。它会在此处显示警告消息。这里有什么问题吗?请帮我解决这个问题。

的login.html

<form name="loginForm">
        <div class="alertmessage" >{{vm.message}}</div>
            <md-input-container flex md-no-float>
                <input ng-model="vm.form.username" placeholder="Username" translate
                       translate-attr-placeholder="LOGIN.USERNAME" name="username" required="true">
                       <div ng-messages="loginForm.username.$error" ng-show="loginForm.username.$touched">
                            <div ng-message="required">This field is required</div>
                        </div>
            </md-input-container>


            <md-input-container flex md-no-float>
                <input ng-model="vm.form.password" type="password" placeholder="Password" translate
                       translate-attr-placeholder="LOGIN.PASSWORD" name="password" required="true">
                       <div ng-messages="loginForm.password.$error" ng-show="loginForm.password.$touched">
                            <div ng-message="required">This field is required</div>
                        </div>
            </md-input-container>

            <div class="remember-forgot-password" layout="row" layout-sm="column"
                 layout-align="space-between center">
                <md-checkbox class="remember-me" ng-model="data.cb1" aria-label="Remember Me">
                    <span translate="LOGIN.REMEMBER_ME">Remember Me</span>
                </md-checkbox>

                <a ui-sref="app.pages_auth_forgot-password" class="forgot-password md-accent-color"
                   translate="LOGIN.FORGOT_PASSWORD">Forgot Password?</a>
            </div>

            <md-button class="md-raised md-accent" aria-label="LOG IN" translate="LOGIN.LOG_IN"
                       translate-attr-aria-label="LOGIN.LOG_IN"
                       ng-click="vm.submitPost(vm.form);">
                LOG IN
            </md-button>
        </form>

2 个答案:

答案 0 :(得分:0)

请验证&#39; userData&#39;的价值是多少?来自前端/来自你呼叫它的地方。似乎只有一个问题!

如果那不是问题那么请检查开发人员工具中的网络,了解您的服务失败的原因?

  

要转到网络(在Chrome上),请点击F12&gt;&gt;网络

验证您的服务电话,看看问题是什么!

编辑:

  

你的标题在哪里&#39;在服务电话?你是故意添加还是错过了它?

答案 1 :(得分:0)

This is one more image of network tab当我在登录后点击它显示如下

When i click after login it showed like this

网络标签图像显示如下

Network tab image showing like this