[英]AJAX call not working(jquery)
我正在尝试从openweathermap网站获取JSON数据,下面是我编写的jQuery代码,我的目标是将JSON数据记录在控制台中,但是控制台日志什么也没显示。通过使用警报功能是否正常工作。但是没有显示警报对话框。我无法确定问题出在哪里。请帮帮我。
$(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>");
}
}
您使用http协议(不是https)的API链接。 因此,可能是发生混合内容错误的原因。
这就是为什么您看不到任何东西或在某些浏览器中注意到某些不安全内容被隐藏的原因。
因此,可能的解决方案是在您的网站上使用http以避免混合内容。 但是强烈建议在两台服务器上都使用https。
我知道这是一篇较旧的文章,但我遇到了同样的问题。 对我有用的是使用
.done(function(data){
console.log(data)}
代替
success:function(data){
console.log(data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.