I am facing an issue with my HTML page that includes Google ADWords and an ajax call from an external URL to retrieve JSON data. The external API has been created by me, and the API Controller in Laravel 5.2 looks like this:
public function index()
{
$data = WeatherData::orderBy('created_at', 'DESC')->first();
return Response::json($data);
}
The HTML ADWords Code causing trouble is:
$.ajax({
url: 'https://weather.mnsc.com/api/v1/data',
type: 'POST',
dataType: 'JSON',
cors: true,
success: function (data) {
console.log(data);
}
});
Unfortunately, when testing in Chrome, I receive the following error message:
XMLHttpRequest cannot load . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500.
I am wondering if there is a specific header that needs to be set in the Laravel API to resolve this issue?