TypeError:$ http.post(...)。success不是函数

时间:2017-10-07 17:58:56

标签: angularjs

点击注册按钮后,网站显示成功不是功能错误。 因为它没有注册 请帮忙!

这是错误

    angular.js:14525 TypeError: $http.post(...).success is not a function
    at b.$scope.register (chirpapp.js:63)
    at fn (eval at compile (angular.js:15358), <anonymous>:4:144)
    at e (angular.js:26994)
    at b.$eval (angular.js:18161)
    at b.$apply (angular.js:18261)
    at HTMLFormElement.<anonymous> (angular.js:26999)
    at HTMLFormElement.dispatch (jquery.min.js:3)
    at HTMLFormElement.q.handle (jquery.min.js:3)
(anonymous) @ angular.js:14525
(anonymous) @ angular.js:11008
$apply @ angular.js:18266
(anonymous) @ angular.js:26999
dispatch @ jquery.min.js:3
q.handle @ jquery.min.js:3

这是我的app.js

var app = angular.module('chirpApp', ['ngRoute']).run(function($rootScope){
     $rootScope.authenticated = false;
  $rootScope.current_user = ''; 
});


app.config(function($routeProvider){
  $routeProvider
    //the timeline display
    .when('/', {
      templateUrl: 'main.html',
      controller: 'mainController'
    })
    //the login display
    .when('/login', {
      templateUrl: 'login.html',
      controller: 'authController'
    })
    //the signup display
    .when('/register', {
      templateUrl: 'register.html',
      controller: 'authController'
    });
});

app.controller('mainController', function ($scope) {
    $scope.posts = [];
    $scope.newPost = {
        created_by: '',
        text: '',
        created_at: ''
    };

    $scope.post = function () {
        $scope.newPost.created_at = Date.now();
        $scope.posts.push($scope.newPost);
        $scope.newPost = {
            created_by: '',
            text: '',
            created_at: ''
        };
    };
});

app.controller('authController', function($scope, $http, $rootScope, $location){
  $scope.user = {username: '', password: ''};
  $scope.error_message = '';

  $scope.login = function(){
    $http.post('/auth/login', $scope.user).success(function(data){
      if(data.state == 'success'){
        $rootScope.authenticated = true;
        $rootScope.current_user = data.user.username;
        $location.path('/');
      }
      else{
        $scope.error_message = data.message;
      }
    });
  };

  $scope.register = function(){
    $http.post('/auth/signup', $scope.user).success(function(data){
      if(data.state == 'success'){
        $rootScope.authenticated = true;
        $rootScope.current_user = data.user.username;
        $location.path('/');
      }
      else{
        $scope.error_message = data.message;
      }
    });
  };
});

点击注册按钮后,网站显示成功不是功能错误。 因为它没有注册 请帮忙! ckech“authcontroller”错误在寄存器中,所以它可能在$ scope.register = function(...)

0 个答案:

没有答案