简体   繁体   中英

AngularJS $http callback not firing

$scope.submitNewUser = function() { 
            $http({
                method: 'POST',
                url: 'api/user/signup',
                data: {'user': $scope.user},
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},                 
            }).success(function(data, status, headers, config) {
                console.log('hello');
                alert('boo');
            });
        }

I have the above and when its ran the POST works but I'm unable to get the .success() part to work, there is no callback and the console.log() and alert() do not fire.

Thanks

try adding the error handler

      console.log("calling http;")
      $http({
            method: 'POST',
            url: 'api/user/signup',
            data: {'user': $scope.user},
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},                 
        }).success(function(data, status, headers, config) {
            console.log('success', data, status);
        }).error(function(data, status, headers, config) {
            console.log('error', data, status);
        }).catch(function(error){
            console.log('catch', error);
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM