1
I am studying angular and I am trying to receive data in JSON format from a webservice, but is with the following error:
Xmlhttprequest cannot load http://localhost:8080/Newspaper/data/newspaper. In the 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost' is therefore not allowed access.
Follow my Cod down.
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!";
});
});
This Chrome app will save you: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
– MarioAleo
Dude I believe you can use a direct HTTP protocol instead of Xmlhttprequest because it works in a similar and more practical way for conversations between server and client;
– Gunblades