$(document).ready(function(){
var long1;
var lat;
var ftemp;
var ctemp;
var ktemp;
$.getJSON("http://ip-api.com/json",function(data2){
lat=data2.lat;
long1=data2.lon;
var api='http://api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+long1+'&appid=46fdba69aa7710295a227debc481af55';
$.getJSON(api,function(data){
var weatherType=data.weather[0].description;
ktemp=data.main.temp;
var windspeed=data.wind.speed;
var city=data.name;
var tempswap=true;
ftemp=((ktemp)*(9/5)-459.67).toFixed(2);//temp in fahrenheit
ctemp=(ktemp-273).toFixed(2);//temp in calcius
console.log(city);
$("#city").html(city);
$("#weatherType").html(weatherType);
$("#ftemp").html(ftemp);
$("#ftemp").click(function(){
if(tempswap===false){
$("#ftemp").html(ftemp+" ℉ ;");
tempswap=true;
}else{
$("#ftemp").html(ctemp+" ℃ ;");
tempswap=false;
}
});
windspeed =(2.237*(windspeed)).toFixed(1);
$("#windspeed").html(windspeed + " mph");
if(ftemp>80){
}else if(ftemp>70){
$('body').css('background-image','url()');
}
});
});
});
我不知道什么是错的。我什么都不能工作(即使控制台不工作)。如何解决为什么以下jQuery代码不起作用?
您需要更具体的实际问题是什么
http
请求被阻塞。你想做什么? – Ken您的代码在控制台中返回错误... 混合内容:'https://codepen.io/manash23/pen/oWmKje?editors=1010'页面通过HTTPS加载,但请求不安全的XMLHttpRequest端点'http://ip-api.com/json'。此请求已被阻止;内容必须通过HTTPS提供。 – Ken