I have a node.js server which is running locally on my computer. And I am developing html page with js-code:
var MainController = function($scope, $http) {
var onCountComplete = function(response) {
$scope.count = response.data;
};
var onError = function(reason) {
$scope.error = "Could not fetch data";
};
$http.get("http://localhost:1337/api/count")
.then(onCountComplete, onError);
$scope.message = "hello";
};
I get the error when I were running this code:
XMLHttpRequest cannot load
http://localhost:1337/api/count
. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'file://' is therefore not allowed access.
I have tried to launch the Chrome with --allow-file-access-from-files key, but it doesn't helps. Is there a way to avoid this error during development?