我想從openweathermap網站獲取JSON數據。下面是我寫過的jQuery代碼。我的目標是在控制檯中記錄JSON數據。但是控制檯日誌沒有顯示任何內容。我嘗試了使用警報是否成功功能是否正常工作。但警報對話框沒有顯示出來。我無法找出問題所在。請幫助我。AJAX調用不工作(jQuery)
$(document).ready(function(){
$("#submitButton").click(function(){
//alert("Hello");
return getWeather();
});
});
function getWeather(){
var city=$("#city").val();
if(city != ''){
$.ajax({
url : 'http://api.openweathermap.org/data/2.5/weather?q=' + city + "&units=metric" + "&APPID=8eca04841762dd31f99510429e97970a",
type:"GET",
dataType:"jsonp",
success:function(data){
//alert("hello");
console.log(data);
$("#showWeather").html();
}
});
}
else{
$("#error").html("<div>City field cannot be empty</div>");
}
}
使用
當您調試這在瀏覽器的調試工具,什麼是AJAX請求的網絡響應? – David除了''success''回調處理程序外,您還可以實現一個''error''回調處理程序並記錄結果。 –
@大衛,這是顯示請求待定 –