我在MVC 5佈局頁面中有一個基本指令,用於搜索指令。我的問題是,無法加載templateUrl(400錯誤)。如果我直接在瀏覽器中輸入URL,我可以毫無困難地加載html頁面。我找不到爲什麼AJAX調用加載頁面失敗。AngularJS指令templateUrl通過文件URL加載返回400.
鉻調試
這是Chrome的HTML頁面加載
app.js
(function() {
var app = angular.module("mainApp");
app.directive("basicSearch", function() {
return {
templateUrl: 'app/directives/basic-search.html',
controller: function($scope, search) {
$scope.keyword = '';
$scope.exact = false;
$scope.submitSearch = function() {
search.searchByKeyword($scope.keyword, 0, $scope.exact);
}
}
}
});
}());
基本-search.html
<div>
<input type="search" ng-model="keyword" name="keyword" />
<button type="submit" ng-click="submitSearch()"></button>
<input type="checkbox"ng-model="exact" name="exact" />
<label for="exact">Exact Match?</label>
</div>
_Layout.cshtml
<html>
<head>
<base href="@Request.ApplicationPath" />
<!--- JS & CS References -->
<title></title>
</head>
<body ng-app="mainApp">
<!-- Other stuff -->
<basic-search></basic-search>
<!-- More other stuff -->
@RenderBody()
</body>
</html>
編輯 這裏是成功的請求(通過瀏覽器):
,這裏是失敗的人(通過Angular指令):
比較兩種情況下的標頭,可能有差異。 – dfsq 2015-02-09 18:19:10
該模板位於要提供的靜態文件夾中?如果您無法通過瀏覽器中的url訪問普通模板,則角度不能太... – 2015-02-09 18:25:42
我可以訪問它。請參閱**網址加載**部分。 – 2015-02-09 18:28:32