I have a HTML
page with Google ADWords in it, and an ajax
call from an external URL, and I want to get the json
data from the url.
The external API
is also made by me.
The API Controller
(in Laravel 5.2
):
public function index()
{
$data = WeatherData::orderBy('created_at', 'DESC')->first();
return Response::json($data);
}
HTML ADWords Code:
$.ajax({
url: 'https://weather.mnsc.com/api/v1/data',
type: 'POST',
dataType: 'JSON',
cors: true,
success: function (data) {
console.log(data);
}
});
But I get an error in Chrome:
XMLHttpRequest cannot load https://weather.mnsc.com/api/v1/data. 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.
Is there a header I need to set in Laravel API?