我无法获取当前使用api的时间
问题描述:
我正在使用我的代码进行预测。我也想获得时间。 我如何获得时间?我无法获取当前使用api的时间
我的代码:
function Get() {
var txtCity = document.getElementById("txtCity").value;
var weather = new XMLHttpRequest();
weather.open("GET", "http://api.wunderground.com/api/df3f2ab5e1db8f97/conditions/q/"+txtCity+".json", false);
weather.send(null);
var r = JSON.parse(weather.response);
var dis = "Current location: " + r.current_observation.display_location.full + "<p>";
dis += "current temp: " + r.current_observation.temperature_string + "<p>";
dis += "current wind speed: " + r.current_observation.wind_string + "<p>";
dis += "current time: " + r.current_observation.time_string;//returns undefined
document.getElementById("weather").innerHTML = dis;
}
答
检查文档:http://www.wunderground.com/weather/api/d/docs?d=data/conditions
TIME_STRING不响应,但observation_time是。
替换此:
...
dis += "current time: " + r.current_observation.time_string;
...
有了这个:
...
dis += "current time: " + r.current_observation.observation_time;
...
'weather.responseText' – Musa
我不明白你怎么个意思 –
'weather.response'是类型化的反应,因为你没不指定响应类型只有responseText将可用。 – Musa