我得到以下在我的控制檯爲什麼我的AJAX調用將網頁主機添加到網址?
GET http://localhost/FCC%20Projects/Show%20Local%20Weather/api.openweathermap.o…9999&lat=43.3104064&APPID=4c45bb0e6071b74cf43da0d4aa498377&_=1440245698059 404 (Not Found)
,如果我拿出http://localhost/FCC%20Projects/Show%20Local%20Weather/
部分並粘貼到瀏覽器欄剩餘的,我從API服務的正確響應。 我在gh-pages上遇到同樣的問題,除了它的前綴是GitHub地址。 http://adoyle2014.github.io/FCC-ShowLocalWeather/
function apiCall(lat, long) {
$.ajax({
url: "api.openweathermap.org/data/2.5/weather?",
jsonp: "jsonp",
dataType: "jsonp",
data: {
lon: long,
lat: lat,
APPID: apiKey
},
success: function (response) {
parseWeather(response);
}
});
爲什麼這個API調用前面加上當前網站地址的網址?
只需以'http://'開頭。更長的解釋作爲答案! –