I am studying angular and I am trying to receive JSON data from a webservice, but it has the following error:
XMLHttpRequest can not load link . At the 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' is therefore not allowed access.
Follow my cod below.
app.controller("jornalCtrl", function($scope, $http) {
var url = 'http://localhost:8080/newspaper/dados/jornal';
$http({
method: 'JSONP',
url: url,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Origin': '*'
},
params: {
format: 'jsonp',
callback: 'JSON_CALLBACK'
}
})
.then(function successCallback(response) {
$scope.jornais = response.jornais.jornal;
},
function errorCallback(response) {
$scope.content = "Something went wrong!";
});
});