我有一個非常簡單的角度JS應用AngularJS錯誤:跨起源請求只支持協議方案:HTTP,數據,鍍鉻的擴展,HTTPS
的index.html
<!DOCTYPE html>
<html ng-app="gemStore">
<head>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js'></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="StoreController as store">
<div class="list-group-item" ng-repeat="product in store.products">
<h3>{{product.name}} <em class="pull-right">{{product.price | currency}}</em></h3>
</div>
<product-color></product-color>
</body>
</html>
的三個文件
產品color.html
<div class="list-group-item">
<h3>Hello <em class="pull-right">Brother</em></h3>
</div>
個app.js
(function() {
var app = angular.module('gemStore', []);
app.controller('StoreController', function($http){
this.products = gem;
}
);
app.directive('productColor', function() {
return {
restrict: 'E', //Element Directive
templateUrl: 'product-color.html'
};
}
);
var gem = [
{
name: "Shirt",
price: 23.11,
color: "Blue"
},
{
name: "Jeans",
price: 5.09,
color: "Red"
}
];
})();
,我開始收到此錯誤,當我進入了一個使用名爲productColor定製指令包括產品color.html的:
XMLHttpRequest cannot load file:///C:/product-color.html. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.
angular.js:11594 Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/product-color.html'.
什麼可能去錯了嗎?這是product-color.html的路徑問題嗎?
我所有的三個文件是在同一個根文件夾C:/user/project/
只是一個快速的指針,如果你做一些愚蠢的事,比如在我的情況我不小心附加的TLD的端口:「HTTP://本地主機:8070.com」那麼你會收到同樣的錯誤。檢查您嘗試解決的URL! – Wildhoney
也許在這裏類似: http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local/38320697#38320697 –
可能[「只有HTTP支持跨源請求」。加載本地文件時出錯](https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local) – vaxquis