mercredi 23 novembre 2016

Error when Update - PUT redux

Good afternoon,

I have a problem. I am working with laravel 5, redux, php7, Ubuntu 16.04. I build a api, http://my_domain/api. In my project I'm showing the results in API, and I can create a new element, but when I want update, I can. I see a error.

Fetch API cannot load http://my_domain/api/6. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
:3000/e/6:1
 Uncaught (in promise) TypeError: Failed to fetch

In my action I have:

export function fetchByArrayEdit(id, contacts) {
    return function(dispatch) {
        console.info(contacts, 'fechtbyarray');
        return fetch(`http://my_domain/api/${id}`, {
            method: "PUT", body: contacts })
            .then(response => response.json())
            .then(json => dispatch(receiveByQuerystring(json)));
    }
}

and in my api I have:

  header('Access-Control-Allow-Origin: *');
  header("Access-Control-Allow-Credentials: true");
  header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
  header('Access-Control-Max-Age: 1000');
  header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization');

What I'm doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire