ログインページのコントローラを作成しました。ここに私のコントローラは次のとおりです。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);
という行については未定義と言った。それは赤ではないので、エラーではありません。なぜそれは何も印刷しないのですか?
'console.log'は' response。$ statusText'の結果を 'undefined..'で表示する必要があります – Rayon
@ Rayonそれはポストリクエストです、どのようにレスポンスが未定義ですか? – Nasreddin
このようなものが得られたら、 'console.log(response);'を実行すると、オブジェクト内のすべてを見ることができます。 – rgvassar