S
S
Stanislav Chernomorchenko2015-09-23 10:24:31
Angular
Stanislav Chernomorchenko, 2015-09-23 10:24:31

Angular $resource how to send your header?

In general, you need to send a request to the server indicating the Header in which I pass several parameters. It seems that I do everything as in the documentation, but the server returns an access denied. So I want to consult with someone who knows, maybe I made a mistake or sent the request incorrectly.

app.controller('groupListCtrl', function($scope, $resource){
    $resource("http://server-adress", {}
        ,{
            POST: {method: 'POST', cache: false, isArray: true, headers:{
                'Content-Type': 'application/json',
                'Authorization': 'Token token="set_user_token"'
            }}
        }).POST(
        function succes(data){
           console.log(data)
        });

});

In response, I get the following error.
XMLHttpRequest cannot load server address. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' localhost:63342 ' is therefore not allowed access. The response had HTTP status code 404.
In server policy, allowed XMLHttpRequest from third party domains.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bromzh, 2015-09-25
@bromzh

404, check the address. And check if the server sends headers

Access-Control-Allow-Origin: http://foo.example
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: X-PINGOTHER
Access-Control-Max-Age: 1728000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question