0

I'm struggling with this problem for over 5 hours. so please help :)

My front-end stack is Angularjs & My back-end stack is LAMP with Laravel framework.

The problem I have is that when I want to send a GET request with $http service in a ui-router resolver as a dependency, firefox throws error : The Same Origin Policy disallows reading the remote resource

but I have configured my backend with barryvdh/laravel-cors package in order to use its middleware to set proper headers.

Angular code snippet :

$http.post('http://example.com', data)
    .then(function (data, status, headers, config) {

    },
    function (data, status, headers, config) {

    });

Laravel code snippet :

//controller constructor
public function __construct()
{
    //parent::__construct();

    $this->middleware('cors');
}

Its a really simple and normal code, I don't know why it doesn't work.

This is my log of HTTP request/response :

enter image description here

I don't know why the CORS headers are not present although they are present in server log.

Ramin Omrani
  • 3,673
  • 8
  • 34
  • 60
  • We need to see the HTTP response from the server for more information. – alcfeoh Oct 12 '15 at 18:47
  • i would check for access-control-allow-origin header on the page from where this request goes out. i had this issues once, and i solved it by moving the code that makes the get request to the server. – srrvnn Oct 12 '15 at 18:47
  • Check the headers in the preflight OPTIONS request and make sure OPTIONS are honored – charlietfl Oct 12 '15 at 18:48
  • @charlietfl updated question – Ramin Omrani Oct 12 '15 at 19:07
  • @srrvnn updated question – Ramin Omrani Oct 12 '15 at 19:07
  • @alcfeoh updated question – Ramin Omrani Oct 12 '15 at 19:07
  • 1
    I don't know laravel but none of the access control headers are there. For pure php solution see http://stackoverflow.com/a/9866124/1175966 – charlietfl Oct 12 '15 at 19:09
  • Your screenshot shows that you get a 400 Bad Request response – and I doubt that this is only the browser saying that because of the SOP violation, but think it is rather your server responding with that status code to begin with – and therefor it is likely that your attempt to send CORS headers doesn’t even get applied, because it errors before it comes to that already. Go check your Laravel and server error log files. – CBroe Oct 12 '15 at 19:30

1 Answers1

1

You have to check if your server sends that header: Access-Control-Allow-Origin "*"

if your server doesn't send it, your browser will fail when open a connection to another domain.

Another options you have is to use grunt-connect-proxy plugin, in case you are using grunt.

Check this link. http://www.hierax.org/2014/01/grunt-proxy-setup-for-yeoman.html

Serginho
  • 7,291
  • 2
  • 27
  • 52
  • 1
    Well...the same! Your server doesn't send Access-Control-Allow-Origin. That options is configured on the server, your can send that header using php but...it seems doesn't work. Configure your server to send that header, or use a proxy to solve it. – Serginho Oct 12 '15 at 19:16