我想从JSON文件中获取信息,但数据变量中没有任何内容。任何人都可以告诉我我做错了什么。 JSON文件被下载,所以没有问题,我没有从服务器获取任何东西。jQuery JSON获取问题
function handle_geolocation_query(position) {
var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + position.coords.latitude + "&lng=" + position.coords.longitude + "&callback=?";
$.getJSON(url, function(info){
var clouds = info.weatherObservation.clouds;
var weather = info.weatherObservation.weatherCondition;
var temp = info.weatherObservation.temperature;
var humidity = info.weatherObservation.humidity;
});
//console.log(clouds);
document.getElementById('result').innerHTML = "C:" + clouds + ", W:" + weather + ", T:" + temp + ", H:" + humidity;
}
欣赏所有的帮助。 非常感谢。
与萤火虫可以检查网面板,是回馈您正在访问同一个结构上的JSON标签的阵列。 – kobe 2010-12-01 05:55:25
无论如何,你正在使用jQuery,使用.html()而不是.innerhtml,你可以simloy say('#result')。html();是weatherObservation一个对象或单个对象的数组。 – kobe 2010-12-01 05:56:29