【发布时间】:2017-05-18 08:10:21
【问题描述】:
我正在从我的网页进行 ajax 调用,以从 getWeather.php 页面以 JSON 格式获取响应。有时我得到结果,但大多数情况下我没有。但是每当我浏览这个链接时,它总是给我 JSON 格式的结果。我在 getWeather.php 中做错了吗?
https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%27lahore%27)%20AND%20u%3D%27c%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
getWeather.php 实现:
<?php
$city = $_GET['city'];
echo file_get_contents("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%27".$city."%27)%20AND%20u%3D%27c%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
?>
{"query":{"count":0,"created":"2017-01-03T04:50:27Z","lang":"en-US","results":null}}
【问题讨论】:
-
确保城市不为空,否则此代码可以正常工作。
-
我什至在查询中写了城市名称进行测试,但有时我得到结果,有时我没有。
标签: php yahoo-weather-api