我试图显示从2个位置(其中有地理编码API检索到的纬度/经度值)的JQuery Dark Sky Forecast API中获取的天气信息。我设法获取纬度/经度数据,但从预测API中被拒绝。控制台日志显示错误信息为:Dark Sky Forecast API不返回数据?
的XMLHttpRequest不能加载https://api.forecast.io/forecast/260960a77daa4006fe463ae709efed95/[object%20HTMLInputElement],[object%20HTMLInputElement]'。请求的资源上没有“Access-Control-Allow-Origin”标题。因此不允许原产地'null'访问。响应有HTTP状态代码400
的代码如下:
//Call Geocoding API to find lat/lng value
$.ajax({
url:"https://maps.googleapis.com/maps/api/geocode/json?address="+fromLocation+"&key=AIzaSyBeUYP6E-zxXWzTzyvuUtUolGLUWy7Jneg",
type: "GET",
success: function(res){
var fromLat = console.log(res.results[0].geometry.location.lat);
var fromLng = console.log(res.results[0].geometry.location.lng);
//call next ajax function
$.ajax({
url:"https://maps.googleapis.com/maps/api/geocode/json?address="+toLocation+"&key=AIzaSyBeUYP6E-zxXWzTzyvuUtUolGLUWy7Jneg",
type: "GET",
success: function(res){
var toLat = console.log(res.results[0].geometry.location.lat);
var toLng = console.log(res.results[0].geometry.location.lng);
}
});
}
});
//Call Forecast API for weather value
$.ajax({
url:'https://api.forecast.io/forecast/260960a77daa4006fe463ae709efed95/'+fromLat+','+fromLng+"'",
type: "GET",
success: function(res){
console.log(res);
}
})
是否有格式错误,而不是一个API? 预先感谢并对格式感到抱歉。