2
I’m trying to access a EndPoint through the Angularjs.
This is my Service:
angular.module('empresa-view')
.factory('empresaService', ['$resource', function ($resource) {
return $resource($SERVICES_CONTEXT + 'empresa/:params', {}, {
update: {
method: "PUT"
},
lista: {
method: 'GET',
params: {params: 'list'},
isArray: true
}
});
}]);
When I run the application of the following error:
GET XHR http://localhost:8080/Exemplovraptor/company [HTTP/1.1 405 Method Not Allowed 5 ms] error[Object Object] main.js:12:21 Request cross-origin blocked: The same origin policy (Same Origin Policy) prevents reading the remote resource on http://localhost:8080/Exemplovraptor/company. (Reason: the header CORS 'Access-Control-Allow-Origin' is not present).
But if I change the empresa/:params for empresa/list' works and I can display take the data. Because the params is not working?
I already have a CORS. This is the complete endpoint:
http://localhost:8080/ExemploVraptor/empresa/listo :params should receivelistbut does not receive. If I put thelistright in place of :params works– DiegoAugusto
From the detail of the error in your reply, it is clear that the error is server permission, if it does not work, it is probably some apache configuration that is not configured for CORS use: no
.htaccess, do this:Header set Access-Control-Allow-Origin "*"– Ivan Ferrer
then it would be better if I passed the list directly instead of passing it as parameter?
– DiegoAugusto
would be asism:
return $resource($SERVICES_CONTEXT + 'empresa/list', {}, {– DiegoAugusto
If you are already passing the parameter in the json collection, you do not need to pass it in the url. Look at the answer for an example.
– Ivan Ferrer