I'm trying to use XAMPP with the following snippets:
The php:
<?php
$api_endpoint = 'https://api.forecast.io/forecast';
$api_key = 'my-api-key';
$url = $api_endpoint . '/' . $api_key . '/' . '37.8267,-122.423';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$curl_response = curl_exec($curl);
curl_close($curl);
echo json_encode($curl_response);
?>
The JSON itself looks like this:
{
latitude: 37.8267,
longitude: -122.423,
timezone: "America/Los_Angeles",
offset: -7,
currently: {
time: 1468248192,
summary: "Clear",
icon: "clear-day"
}
}
The javascript:
$(document).ready(function(){
$('#myButton').click(function(e){
e.preventDefault();
$('#myButton').fadeOut(300);
$.ajax({
url: 'php/forecast.php',
type: 'GET',
dataType: 'json',
success: function(data, status) {
$('#content').html(data.latitude);
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "
Error:" + err);
}
});
});
});
I works perfectly on a live server, but when using XAMPP I keep getting the error Unexpected end of JSON input. Has anyone ran into this issue before with XAMPP? Any thoughts on what could be causing this?