我創建了一個小的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代碼不會被調用