I am using Laravel 5 and a library called CORS. I am facing an error that I don't really understand what it is and why it is happening.
I am developing an API that is gonna be used by a website's front-end and an app.
I am trying to do an ajax call to the API:
$.ajax({
url: 'http://myapi.com/call',
type: 'GET',
headers: {'Authorization' : 'Bearer token123'},
crossDomain: true,
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
success : function(data) { console.log(data);},
error: function(xhr) {console.log(xhr)}
});
However I got this errro:
XMLHttpRequest cannot load http://myapi.com/call. Response for preflight has invalid HTTP status code 500
However, when I remove the following line from the request works fine.
headers: {'Authorization' : 'Bearer token123'},
EDIT: my config/cors.php
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
'exposedHeaders' => [],
'maxAge' => 0,
'hosts' => [],
Any idea about how to solve it?