This is my code:
MyAppModule.factory('EventData', function($http,$log){
return {
getEvent : function(successcb){
$http({method: 'GET', url: './js/Services/products.json'}).
success(function(data) {
$log.info("success");
}).
error(function(data) {
$log.info("error");
});
}
};
});
I have a simple JSON file in a local location, and I am trying to read it using the http
method of AngularJS. I am getting the following error:
XMLHttpRequest cannot load file:///C:/Users/Avraam/Documents/GitHub/AngularJS/app/js/Services/products.json Cross origin requests are only supported for HTTP. angular.min.js:73
Error: A network error occurred.
What is my mistake? I am not using any server; I am just openning my index file with Chrome. Is this the mistake? Should I use a server if I want to use the http
method?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…