"No 'Access-Control-Allow-Origin' header is present" cakephp

Asked

Viewed 1,510 times

0

Good morning, everyone

I’m making an application with angular and cakephp. I am trying to make a request for the backend and the following message appears on the console:

Xmlhttprequest cannot load http://localhost:8765/api/v1/users/client.json? client_id=cliente&client_secret=secret. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost:8080' is therefore not allowed access.

my controller

.controller('loginCtrl', ['$scope', '$stateParams', '$http', '$location', function ($scope, $stateParams, $http, $location) {

$scope.fazerLogin = function(usuario){
    //console.log(usuario);
    //http://localhost:8765/api/v1/users/client.json?client_id=cliente&client_secret=segredo"
    var url = "";
    var cid = "cliente";
    var cs = "segredo";
    $http.post("http://localhost:8765/api/v1/users/client.json?client_id="+cid+"&client_secret="+cs).success(function(data){
        console.log(data);
    });

}


}])

my php

<?php
public function beforeFilter()
{

   parent::beforeFilter();
           $this->response->header('Access-Control-Allow-Origin','*');
           $this->response->header('Access-Control-Allow-Methods','*');
           $this->response->header('Access-Control-Allow-Headers','X-Requested-With');
           $this->response->header('Access-Control-Allow-Headers','Content-Type, x-xsrf-token');
           $this->response->header('Access-Control-Max-Age','172800');
}
?>

Where I have to make the adjustment in my php?

2 answers

1


0

In the endpoint of your service add:

$this->response->header('Access-Control-Allow-Origin', '*');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.