2017-10-26 2 views
0

Ich verzichte auf WCF-Service auf Angular Js-Anwendung. Ich retrive Liste der Datensätze von SQL-Datenbank basierend auf Text auf Eingabe-Feld, aber wenn ich die Nummer Eingabefeld eingeben und klicken Sie auf die Schaltfläche Suche. Ich habe folgende Fehler in Google Chorme in Konsolenfenster ..Angular JS-Anwendung POST.Success ist keine Funktion mit Wcf-REST-Service

angular.js:14642 TypeError: post.success is not a function 
    at b.$scope.Search (Search.js:13) 
    at fn (eval at compile (angular.js:15500), <anonymous>:4:138) 
    at e (angular.js:27285) 
    at b.$eval (angular.js:18372) 
    at b.$apply (angular.js:18472) 
    at HTMLInputElement.<anonymous> (angular.js:27290) 
    at kg (angular.js:3771) 
    at HTMLInputElement.d (angular.js:3759) 

Hier ist die Schnittstelle ..

[OperationContract] 
     string GetCustomers(string prefix); 

Hier ist die Umsetzung ist.

public string GetCustomers(string prefix) 
{ 
    List<object> customers = new List<object>(); 
    string sql = "SELECT * FROM Current_Account_Details WHERE Account_Number LIKE @prefix + '%'"; 
    using (SqlConnection conn = new SqlConnection()) 
    { 
     conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; 
     using (SqlCommand cmd = new SqlCommand(sql)) 
     { 
      cmd.Parameters.AddWithValue("@prefix", prefix); 
      cmd.Connection = conn; 
      conn.Open(); 
      using (SqlDataReader sdr = cmd.ExecuteReader()) 
      { 
       while (sdr.Read()) 
       { 
        customers.Add(new 
        { 
         Account_Number = sdr["Account_Number"], 
         Account_Creation_Date = sdr["Account_Creation_Date"], 
         Account_Type = sdr["Account_Type"], 
         Branch_Sort_Code = sdr["Branch_Sort_Code"], 
         Account_Fees = sdr["Account_Fees"], 
         Account_Balance = sdr["Account_Balance"], 
         Over_Draft_Limit = sdr["Over_Draft_Limit"] 


        }); 
       } 
      } 
      conn.Close(); 
     } 
     return (new JavaScriptSerializer().Serialize(customers)); 
    } 
} 

Hier ist der Code Skript ..

var app = angular.module('MyApp', []) 
app.controller('MyController', function ($scope, $http, $window) { 
    $scope.IsVisible = false; 
    $scope.Search = function() { 
     var post = $http({ 
      method: "POST", 
      url: "http://localhost:52098/HalifaxIISService.svc/GetCustomers", 
      dataType: 'json', 
      data: { prefix: $scope.Prefix }, 
      headers: { "Content-Type": "application/json" } 
     }); 

     post.success(function (data, status) { 
      $scope.Customers = eval(data.d); 
      $scope.IsVisible = true; 
     }); 

     post.error(function (data, status) { 
      $window.alert(data.Message); 
     }); 
    } 
}); 

Hier ist der HTML-Code.

@{ 
    Layout = null; 
} 

<!DOCTYPE html> 

<html> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
    <title>Search</title> 
    <script src="~/Scripts/angular.min.js"></script> 
    <script src="~/RegistrationScript/Search.js"></script> 
</head> 
<body> 
    <div ng-app="MyApp" ng-controller="MyController"> 
     Name: 
     <input type="text" ng-model="Prefix" /> 
     <input type="button" value="Submit" ng-click="Search()" /> 
     <hr /> 
     <table cellpadding="0" cellspacing="0" ng-show="IsVisible"> 
      <tr> 
       <th> Account Number</th> 
       <th>Account Creation date</th> 
       <th>Account Type</th> 
       <th> Sort code</th> 
       <th>Account Fee</th> 
       <th>Account Balance</th> 
       <th>Overdraft Limit</th> 


      </tr> 
      <tbody ng-repeat="m in Customers"> 
       <tr> 
        <td>{{m.Account_Number}}</td> 
        <td>{{m.Account_Creation_Date}}</td> 
        <td>{{m.Account_Type}}</td> 

        <td>{{m.Branch_Sort_Code}}</td> 
        <td>{{m.Account_Fees}}</td> 
        <td>{{m.Account_Balance}}</td> 
        <td>{{m.Over_Draft_Limit}}</td> 

       </tr> 
      </tbody> 
     </table> 
    </div> 
</body> 
</html> 

Hier ist der Screenshot, wenn ich die Anwendung ausführen. Click here to see the result

Antwort

1

mit kantigem 1.4 und oberhalb success und error sind nicht mehr verfügbar ist. stattdessen sollten Sie verwenden. then und .catch.

$scope.Search = function() { 
     var post = $http({ 
      method: "POST", 
      url: "http://localhost:52098/HalifaxIISService.svc/GetCustomers", 
      dataType: 'json', 
      data: { prefix: $scope.Prefix }, 
      headers: { "Content-Type": "application/json" } 
     }).then(function(success) { 
      return genericSuccess(success); 
     });   
    }; 
    function genericSuccess(data) { 
      $scope.Customers = eval(data.d); 
      $scope.IsVisible = true; 
    }); 
+0

wo ich brauche, um macht die Änderungen? – Mohammad

+0

überprüfen Sie die aktualisierten Antwort – Sajeetharan

+0

Angularjs: 14642 Reference: genericSuccess nicht – Mohammad

Verwandte Themen