类型错误:在 ASP.NET 中触发 AJAX 请求时,未定义不是一个函数
TypeError: undefined is not a function when triggering AJAX requests in ASP.NET
我按照这个链接上的教程在我的angularJS应用程序(CRUD操作)上创建AJAX请求。完成编码后,我尝试执行 AJAX 请求(从数据库中获取所有数据),但是当我午餐我的应用程序时,我收到此错误:
TypeError: undefined is not a function
at new <anonymous> (http://localhost:49510/Scripts/application/controllers.js:4:15)
有人知道问题在哪里以及如何解决吗?
这是代码:
控制器:
app.controller('ContactsController', [
'$scope', '$http', '$location', 'contactsService',
function ($scope, $location, $http, contactsService) {
$http.get('/contacts/').success(function (data) { //triggers error
alert(data);
$scope.contact = data;
$scope.loading = false;
})
.error(function () {
alert ("An Error has occured while loading contacts!");
// $scope.loading = false;
});
$scope.editContact = function (id) {
$location.path('/edit-contact/' + id);
};
$scope.displayContact = function (id) {
$location.path('/display-contact/' + id);
};
$scope.showDetails = function (id) {
var el = angular.element(document.getElementById('#ct-details-' + id));
el.toggleClass('details-hidden');
}
}
]);
这是联系人.html模板:
<div class="container view">
<header>
<h3>Contacts</h3>
</header>
<div>
<a class="nav-pills hover" href="#/add-contact">Add Contact</a>
</div>
<br /><br />
<div class="row">
<ul class="span5" >
<li class="nav-pills nav-stacked contact-row" data-ng-repeat="contact in contacts | orderBy:'firstName'">
<span id="ct-details-{{contact.id}}" data-ng-click="displayContact(contact.id)" style="cursor:pointer;" class="contact-data details-hidden" href="" >
<span class="span3 contact-name" >{{contact.firstName + ' ' + contact.lastName}}
{{contact.emailAddress}}</span>
</span>
<button class="btn editContact" data-ng-click="deleteContact(contact.id)">Delete</button>
<button class="btn editContact" data-ng-click="editContact(contact.id)">Edit</button>
</li>
</ul>
</div>
</div>
这是index.cshtml文件:
<!DOCTYPE html>
<html ng-app="contactsManager">
<head>
<title>Contacts</title>
</head>
<body>
<div class="navbar navbar-top">
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/custom.css" rel="stylesheet" />
<div class="navbar-inner">
<div class="container">
<h2>Contacts</h2>
</div>
</div>
</div>
<div ng-view class="example-animate-container"
ng-animate="{enter: 'example-enter', leave: 'example-leave'}"></div>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Scripts/application/application.js"></script>
<script src="~/Scripts/application/controllers.js"></script>
<script src="~/Scripts/application/contactsService.js"></script>
</body>
</html>
控制器函数中的参数顺序必须与参数数组中的顺序匹配。
您混合了$http
和$location
的顺序。
因此,请将函数签名更改为
app.controller('ContactsController', [
'$scope', '$http', '$location', 'contactsService',
function ($scope, $http, $location, contactsService) {
相关文章:
- Jquery未定义函数正在停止其他操作
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- Uncaught ReferenceError:尝试在Android网络视图中访问时未定义函数
- jQuery文件上传和验证未定义函数
- 引用错误:未定义函数-Firefox
- res.render中出错,未定义函数
- 神秘的未定义函数
- 尝试使用函数和Ajax修改值时未定义函数
- 引用错误:未定义函数
- ReferenceError:未定义函数
- 在 Angular JS 中使用 ng-include 的未定义函数
- 未捕获的引用错误:未定义函数
- j查询工具提示引发错误:未定义函数
- 未捕获的引用错误: 未定义单击世界 -- 未定义函数
- JS:引用错误:未定义函数
- 茉莉花未定义函数
- Javascript 错误:未捕获的引用错误:未定义 [函数]
- 未定义函数
- 尽管 js 文件引用在标头中,但未定义函数
- Javascript 未定义函数错误