我試圖顯示從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? 預先感謝並對格式感到抱歉。