1

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.

2 Answers 2

1

It could be a CORS issue did you check if the server has configured the Access-Control-Allow-Origin header.

Sign up to request clarification or add additional context in comments.

4 Comments

It doesn't. I will see when it will be implemented then. thanks
Access-Control-Allow-Origin header is set to *
Hi Jan, I just checked your server(the one in your error message). The error it provides indicates that this is a server-side issue. I think the access control header is not set to * as you assume. I have checked your snippet and it works fine (on another server) you can check this yourself using httpbin.org
Hi, thanks for a help Niels. We used to have it there, now we started playing with its settings and it disappeared again.
0

Simplify Add as below in your controller class

@CrossOrigin(origins = "*") public class Controller {

1 Comment

while code only answers might answer the question in this instance, it is better to include WHY your answer fixes the OP's issue so they can learn from the experience

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.