2

I've been trying to make a search with Angular JS but I get this weird error: TypeError: undefined is not a function and it is on the .success

Here is my code:

<html ng-app="app">
<head>
<meta charset="utf-8">
<script src="angular.js"></script>
<script>
  var app = angular.module('app', []);

  app.controller('ctrl', function ($scope, $http){
      $scope.url = 'fetch.php';
      $scope.search = '';

      $scope.postLink = function(){

        $http.post($scope.url, { "data" : $scope.search}).succes(function(data, status){
          console.log(data);
        }).error(function(data, status) {
          $scope.data = data || "Request failed";
          $scope.status = status;   
        });
      }
  });

</script>
</head>
<body ng-controller="ctrl">
    <input type="text" ng-model="search">
    <input type="submit" ng-click="postLink()">
</body>
</html>

Can anyone tell my why it gives me an error on the .succes? Am I not allowed to call it there?

Thanks in advance!

Bryan
  • 2,870
  • 24
  • 39
  • 44
Consolee Logg
  • 33
  • 1
  • 1
  • 4

3 Answers3

11

It is spelled success.

$http is promised based, so you can also use:
.then for success,
.catch for fail and
.finally in both cases.

See:

Raunak Gupta
  • 10,412
  • 3
  • 58
  • 97
jantimon
  • 36,840
  • 23
  • 122
  • 185
3

There is a typo in the succes function name. Despite that, the success and error functions are now removed as of Angular 1.6 and should be replaced with the standard promise functions .then() / .catch().

More details in this answer: Why are angular $http success/error methods deprecated? Removed from v1.6?

Community
  • 1
  • 1
mcompeau
  • 1,221
  • 1
  • 9
  • 4
1

It's then for $http promises.

At second, you have a typo, it should be success

Guard
  • 6,816
  • 4
  • 38
  • 58