Javascript Angular JS Application POST.Success不是Wcf REST服务的函数
我正在使用wcf服务创建应用程序。我正在根据输入字段上的文本从sql数据库检索记录列表,但当我输入输入字段的编号并单击搜索按钮时。我在控制台窗口中的Google Chorme中发现以下错误Javascript Angular JS Application POST.Success不是Wcf REST服务的函数,javascript,c#,angularjs,wcf,Javascript,C#,Angularjs,Wcf,我正在使用wcf服务创建应用程序。我正在根据输入字段上的文本从sql数据库检索记录列表,但当我输入输入字段的编号并单击搜索按钮时。我在控制台窗口中的Google Chorme中发现以下错误 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), <anonymo
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)
下面是实现
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));
}
}
下面是html代码
@{
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>
@{
布局=空;
}
搜寻
姓名:
帐号
帐户创建日期
帐户类型
排序代码
帐户费
账户余额
透支限额
{{m.Account_Number}
{{m.Account\u Creation\u Date}
{{m.Account_Type}
{{m.Branch\u Sort\u Code}
{{m.账户费用}
{{m.Account_Balance}}
{{m.Over_Draft_Limit}}
这是我运行应用程序时的屏幕截图。
角度1.4及以上的
成功
和错误
不再可用。相反,您应该使用。然后
和.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;
});
需要在哪里进行更改?angular.js:14642 ReferenceError:genericSuccess未定义使用$scope.genericTypeError:$scope.genericSuccess不是函数
@{
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>
$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;
});