【发布时间】:2017-01-11 08:35:19
【问题描述】:
function getCity(city){
$.ajax({
url: 'https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + city + '")',
type: 'GET',
dataType: 'json',
success: function (data) {
var humi = data.query.results.channel.atmosphere.humidity;
var wind = data.query.results.channel.wind.speed;
var temp = data.query.results.channel.item.condition.temp;
temp = Math.floor((temp - 32) * (5 / 9));
wind = Math.floor(wind*1.609344);
$('#temp-get').html(temp+"C°");
$('#humi-get').html(humi+"%");
$('#wind-get').html(wind+"km/h");
},
error: function(){
$('#temp-get').html("Couldn't get info");
$('#humi-get').html("Couldn't get info");
$('#wind-get').html("Couldn't get info");
}
});
}
它总是返回无法获取信息,如果我注释掉错误并删除成功,它仍然不会返回任何内容,但如果我使用:
$.get('https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + city + '")&format=json',
它按应有的方式返回信息,但是我不能使用成功和错误来检查我是否得到了我所知道的信息
【问题讨论】:
-
(1) 阅读您写问题的方框旁边的代码格式说明。 (2) 在浏览器中打开开发者工具,查看控制台。可能会出现一条错误消息,告诉您问题所在。 (3) 在浏览器中打开开发者工具并查看 Network 选项卡:这将告诉您浏览器究竟在请求什么以及服务器返回什么。
标签: javascript ajax get