[英]AngularJS: console.log does not display anything
我寫了一個用於登錄頁面的控制器。 這是我的控制器:
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);
。 這不是錯誤,因為它不是紅色。 為什么不打印任何內容?
使用response.statusText
而不是response.$statusText
。 對於AngularJS $ HTTP請求的文檔列出狀態文本作為響應對象的屬性之一- https://docs.angularjs.org/api/ng/service/ $ HTTP
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.