我创建了一个小的MVC项目,我想通过我的JavaScript控制器检索数据AngularJS与MVC ERR_CONNECTION_REFUSED
我的控制器看起来是这样的: -
angular.module('MyApp', [])
.controller('PlayerCtrl', function ($scope, $http) {
$scope.title = "loading...";
$scope.players = [];
$scope.working = false;
$scope.myString = "ABC";
$scope.getPlayers = function (group) {
$scope.working = true;
$http.get("/api/player").success(function (data, status, headers, config) {
$scope.players = data.players;
}).error(function (data, status, headers, config) {
$scope.title = "Oops... something went wrong";
$scope.working = false;
});
};
});
我的HTML页面看起来像这样: -
@{
ViewBag.Title = "Play";
}
<div id="bodyContainer" ng-app="MyApp">
<section id="content">
<div ng-model="PlayerCtrl" ng-init="getPlayers()">
<p>{{myString}}</p>
<select id="group1">
<option ng-repeat="option in data.players" value="{{option.FirstName}}">{{option.LastName}}</option>
</select>
</div>
</section>
</div>
@section scripts {
@Scripts.Render("~/Scripts/angular.js")
@Scripts.Render("~/Scripts/app/player-controller.js")
}
我可以看到我的JavaScript被击中,因为我已经在Chrome开发人员工具断点
然而,当执行JavaScript的我在开发工具
http://localhost:61176/4181b55e60dd4855bf01360ebafcfd61/browserLink无法加载资源的控制台收到以下错误:净:: ERR_CONNECTION_REFUSED
我不知道为什么。任何指针极大赞赏
注 - 如果我添加/ api /播放器到我的URL测试然后我的.NET代码触发并正确执行。从javascript控制器正常运行时,我的.NET代码不会被调用