Reputation: 1840
I'm trying to set http in AngularJS, but it seems I'm doing something wrong.
app.controller("mainCtrl", function ($scope, $http) {
$http({
method: 'GET',
url: '***',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).success(function (data, status, headers, config) {
console.log("data", data);
console.log("status", status);
console.log("headers", headers);
console.log("config", config);
}).error(function (data, status, headers, config) {
console.log("data", data);
console.log("status", status);
console.log("headers", headers);
console.log("config", config);
})
})
My main interest is to set accept: json
, but if I check the request headers in Google Chrome's dev tools it always just says Accept:\*/\*
.
EDIT: CORS is set on the server and I'm still getting this error no response.
XMLHttpRequest cannot load http://inpro.smid.co.cz:8080/InproRestApi/webresources/entities.regions. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.
Upvotes: 1
Views: 655
Reputation: 11
Simplify Add as below in your controller class
@CrossOrigin(origins = "*") public class Controller {
Upvotes: 0
Reputation: 1603
It could be a CORS issue did you check if the server has configured the Access-Control-Allow-Origin header.
Upvotes: 1