javascript - $http.post (angularjs) 中的未定义函数 : . 成功

标签 javascript php json angularjs post

<分区>

我一直在尝试使用 Angular JS 进行搜索 但是我得到了这个奇怪的错误:TypeError: undefined is not a function 成功了

这是我的代码:

<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>

谁能告诉我为什么它在 .succes 上给我一个错误?我不允许在那里打电话吗?

提前致谢!

最佳答案

拼写为success

$http 是基于 promise 的,因此您还可以使用:
.then 为成功,
.catch 失败和
.finally 在这两种情况下。

参见:

关于javascript - $http.post (angularjs) 中的未定义函数 : . 成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25343831/

相关文章:

json - 用 Ant 解析json

Javascript - 创建正则表达式字符类

php - 正则表达式来匹配蛞蝓?

javascript - 使用 javascript 形成文本框内容

php - __set/__get 数组属性

php - 如何进行查询以获得可区分的值?

json - 简单示例 - Argo 和 Swift 2

JavaScript 异常 :Uncaught TypeError: Converting circular structure to JSON

javascript - 从 javascript 在 Flask 服务器上调用 web 服务方法

javascript - 从 Node.js 运行 python 脚本