【问题标题】:I am getting this error- angular.js:14525 TypeError: $http.post(...).success is not a function我收到此错误 - angular.js:14525 TypeError: $http.post(...).success is not a function
【发布时间】:2017-09-01 15:38:45
【问题描述】:

我收到以下错误**(angular.js:14525 TypeError: $http.post(...).success is not a function atChildScope.BindingCode.$scope.Submit (ClientSide.html:36) at fn (eval at compile (angular.js:15358), :4:138))** 在执行这段代码时。这段代码将对象发送到 asp.net webapi,并在处理后取回数据-

   $scope.Submit = function () {
                    if($scope.Customer.CustomerName.length==0)
                    {
                        alert("Not a proper data");
                    }
                    else
                    {
                        $http.post("http://localhost:59040/api/Customer", $scope.Customer).
                            success(function (data) {
                            $scope.Customer = data;
                        });
                    }
                }

【问题讨论】:

    标签: angularjs asp.net-mvc asp.net-web-api


    【解决方案1】:

    我在使用 angular + asp.net-web-api 的类似解决方案中确实遇到了同样的错误。该错误与angular的版本有关。

    “成功”功能在 Angular 版本 1.6.2 中已弃用

    在这种情况下正确的sintax

       $scope.Submit = function () {
                    if($scope.Customer.CustomerName.length==0)
                    {
                        alert("Not a proper data");
                    }
                    else
                    {
                        $http({
                            method: 'POST',
                            url: 'http://localhost:59040/api/Customer'
                        }).then(function successCallback(data) {
                            $scope.Customer = data;
                        }, function errorCallback(response) {
                            console.log(response);
                        });
                    }
                }
    

    【讨论】:

      猜你喜欢
      • 2015-10-11
      • 1970-01-01
      • 2017-07-22
      • 2020-01-29
      • 1970-01-01
      • 2021-03-28
      • 2020-11-17
      • 2022-10-07
      • 2014-10-06
      相关资源
      最近更新 更多