douzao2992 2016-07-11 15:55
浏览 100
已采纳

XAMPP返回错误“JSON输入的意外结束”

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?

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 有没有可以下载钉钉群文件视频的软件
      • ¥15 如何用LaTeX打出如下的表格
      • ¥15 程序填空补充完整的代码一共三题
      • ¥15 在MySQL中使用while建表,报错
      • ¥15 DB2线上告警,三表联查sql优化。
      • ¥15 python导入pyautogui报错,网上也没有找到解决方法如何解决?
      • ¥15 关于IPSEC和NAT SERVER同时使用的情况下,该如何解决客户端访问服务器的问题
      • ¥15 eclipse项目在idea运行部署到云服务器
      • ¥100 sql server image类型转换
      • ¥15 关于matlab的问题