I have to get JSON data from the below GET Service
http://localhost:8080/test/GetAllLocation
When I hit above URL into my browser this gives me JSON data. But I am unable to get JSON data into my AngularJS application.
My controller code is give below
(function () {
angular
.module('app')
.controller('VisitorsController', [ 'myService', VisitorsController])
.factory("myService", ['$http', function($http) {
return {
getResponders: function(servicesUrl) {
return $http.get(servicesUrl).then(function(response) {
console.log(response.status);
return response.data;
}).catch(function(response) {
console.log(response.status);
return response.data;
});
}
};
return myService;
}]);
function VisitorsController(myService) {
var vm = this;
var servicesUrl = 'http://localhost:8080/test/GetAllLocation';
myService.getResponders(servicesUrl).then(function(data) {
console.log(data);
if(data==null) {
console.log(data);
} else {
console.log(data);
}
}).catch(function(response) {
console.log(response.status);
return response.data;
});
vm.visitorsChartData = [ {key: 'UP', y: 5264}, { key: 'Critical', y: 3872},{key: 'Warning', y: 1000} ];
vm.chartOptions = {
chart: {
type: 'pieChart',
height: 210,
donut: true,
x: function (d) { return d.key; },
y: function (d) { return d.y; },
valueFormat: (d3.format(".0f")),
color: ['rgb(0, 150, 136)', '#E75753','#fbbc05'],
showLabels: false,
showLegend: false,
title: 'Over 9K',
margin: { top: -10 }
}
};
}
})();
When I run this application this will give me below error
AngularJS POST http://localhost:8080/test/GetAllLocation 405 (Method Not Allowed)
XMLHttpRequest cannot load http://localhost:8080/test/GetAllLocation. No 'Access-Control-Allow-Origin' header is present on the requested resource.The response had HTTP status code 405.