2017-04-06 195 views
-3

我得到以下錯誤**(angular.js:14525 TypeError:$ http。 post(...)。成功不是函數atChildScope.BindingCode。$ scope.Submit(ClientSide.html:36)at fn(eval at compile(angular.js:15358),:4:138))** while執行這段代碼。這段代碼被髮送到物體向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; 
         }); 
        } 
       } 

回答

0

我沒有得到相同的錯誤在具有角+ asp.net-的WebAPI的類似的解決方案。該錯誤與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); 
        }); 
       } 
      } 
相關問題