2016-05-01 20 views
0

ログインページのコントローラを作成しました。ここに私のコントローラは次のとおりです。AngularJS:console.logに何も表示されない

var authApp = angular.module('loginApp', []) 

authApp.controller('LoginCtrl', ['$scope', '$location', 'loginFactory', function($scope, $location, loginFactory){ 
    $scope.authenticate = function() { 
     loginFactory.login($scope.username, $scope.password) 
     .then(function(response) { 
      console.log(response.$statusText); 
     }, function errorCallBack(response) { 
      console.log(response.$statusText); 
     }); 
    } 

}]); 

私のサービス:私はコードをデバッグするとき

authApp.factory("loginFactory", function ($http) { 
    return{ 
     login: function(username, password) { 
      var data = "username="+username+"&password="+password+"&submit=Login"; 
      return $http({ 
       method: 'POST', 
       url: 'http://localhost:8080/login', 
       data: data, 
       headers: { 
        'Content-Type': 'application/x-www-form-urlencoded', 
       } 
      }); 
     } 

、認証が成功したようで、それがthen関数に手に入れました。ただし、コンソールには何も表示されません。そして、私は警告(?)を得て、console.log(response.$statusText);という行については未定義と言った。それは赤ではないので、エラーではありません。なぜそれは何も印刷しないのですか?

+1

'console.log'は' response。$ statusText'の結果を 'undefined..'で表示する必要があります – Rayon

+0

@ Rayonそれはポストリクエストです、どのようにレスポンスが未定義ですか? – Nasreddin

+0

このようなものが得られたら、 'console.log(response);'を実行すると、オブジェクト内のすべてを見ることができます。 – rgvassar

答えて

2

response.statusTextresponse.$statusTextを使用してください。 AngularJS $ http要求のドキュメントでは、応答オブジェクトのプロパティの1つとしてstatusTextがリストされています。https://docs.angularjs.org/api/ng/service/ $ http

+0

どうすればいいですか..それは何でもかまいませんが、完璧な推測になるかもしれません... – Rayon

+0

AngularJS http要求のドキュメントには、応答のプロパティの1つとしてstatusText – Cameron637

+1

はい!私はそれを 'server'からの応答オブジェクトとして読んでいました。[__reference__](https://docs.angularjs.org/api/ng/service/$http)を追加したいかもしれません – Rayon

関連する問題